I'm trying to use subs
in maple to replace derivatives in a longer formula with 0:
subs(diff(u(r),r) = 0, formula);
It seems that if formula
only involves first derivatives of u(r)
this works as I expect. For example,
formula := diff(u(r),r);
subs(diff(u(r),r) = 0, formula);
0
But if formula
involves second derivatives I get a diff(0,r)
in the result that won't go away even when using simplify
:
formula := diff(u(r),r,r);
subs(diff(u(r),r) = 0, formula);
d
-- 0
dr
(My actual formula
is quite long involving first and second derivatives of two variables. I know that all derivatives with respect to a certain variable are 0 and I'd like to remove them).
One way is to use the simplify
command with so-called side-relations.
formula := diff(u(r),r,r) + 3*cos(diff(u(r),r,r))
+ diff(u(r),r) + x*(4 - diff(u(r),r,r,r)):
simplify( formula, { diff(u(r),r) = 0 } );
3 + 4 x
formula2 := diff(u(r,s),s,s) + 3*cos(diff(u(r,s),r,r))
+ diff(u(r,s),r) + x*(4 - diff(u(r,s),r,s,r,r)):
simplify( formula2, { diff(u(r,s),r) = 0 } );
/ 2 \
| d |
3 + |---- u(r, s)| + 4 x
| 2 |
\ ds /
[edit] I forgot to answer your additonal query about why you got d/dr 0
before. The answer is because you used subs
instead of 2-argument eval
. The former does purely syntactic substitution, and doesn't evaluate the result. The latter is the one that people often need, without knowing it, and does "evaluation at a (particular) point".
formulaA := diff(u(r),r,r):
subs(diff(u(r),r) = 0, formulaA);
d
--- 0
dr
%; # does an evaluation
0
eval(formulaA, diff(u(r),r) = 0);
0
formulaB := diff(u(r,s),s,r,r,s):
eval(formulaB, diff(u(r,s),r) = 0);
0
You can see that any evaluation of those d/dr 0
objects will produce 0. But it's is often better practice to use 2-argument eval than it is to do eval(subs(...))
. People use subs
because it sounds like "substitution", I guess, or they see others use it. Sometimes subs
is the right tool for the job, so it's important to know the difference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.