52 States in 8 Months

Maple: How to differentiate with respect to x(t)?

Posted in University stuff by Ulf on May 7, 2009

107mapleleafAlthough Matlab is the toy of choice for control engineers, we sometimes have to use Maple or some other symbolic manipulation program. Now, there is one thing about Maple which I absolutely don’t like: If I define a time-dependent variable such as x(t), I cannot directly use Maples symbolic differentiation tool for differentiating w.r.t. x(t):

diff( sin(x(t)), x(t) );
Error, invalid input: diff received x(t), which is not valid for its 2nd argument

 
Today I found a really neat solution on mapleprimes.com. They are simply defining a new function sdiff which basically does what I also did a lot of times, substituting x(t)=x and differentiating w.r.t. x:

sdiff := proc(expr, sym)
local t;
subs(t=sym, diff( subs(sym=t,expr), t) );
end:

 
It is called like this:

sdiff( sin(x(t)), x(t));
cos(x(t))

 
The solution comes from Chapter 12 of the Maple Book by Walter Gander and Jiří Hrebicek. Thank you!

Leave a comment