# How can I get a derivated function df/dt?

74 views (last 30 days)
Felix Lauwaert on 7 Aug 2015
Commented: Star Strider on 7 Aug 2015
Hello,
I'm trying to calculate derivate functions like z(t)=cos(x(t))+y(t)^2 and I expect answers like z'(t)=-x'(t)*sin(x(t))+2*y(t)*y'(t).
I probably need to use MuPAD but I don't know the commands and what I've found on 'help' isn't exactrly what I want.

Star Strider on 7 Aug 2015
In R2015a, I get this result:
syms x(t) y(t) z(t)
z(t)=cos(x(t))+y(t)^2;
dzdt = diff(z, t)
dzdt(t) =
2*y(t)*diff(y(t), t) - sin(x(t))*diff(x(t), t)
##### 1 CommentShowHide None
Star Strider on 7 Aug 2015
It depends on whether it is an additive or multiplicative constant, and where it is in the expression.
Example 1 (multiplicative):
syms x(t) y(t) z(t) c
z(t) = c * cos(x(t)) + y(t)^2;
dzdt = diff(z, t)
dzdt(t) =
2*y(t)*diff(y(t), t) - c*sin(x(t))*diff(x(t), t)
syms x(t) y(t) z(t) c
z(t) = c + cos(x(t)) + y(t)^2;
dzdt = diff(z, t)
dzdt(t) =
2*y(t)*diff(y(t), t) - sin(x(t))*diff(x(t), t)
As expected, it disappears if an additive constant.
Example 3 (multiplicative inside expression):
syms x(t) y(t) z(t) c
z(t) = cos(c*x(t)) + y(t)^2;
dzdt = diff(z, t)
dzdt(t) =
2*y(t)*diff(y(t), t) - c*sin(c*x(t))*diff(x(t), t)
Example 4 (additive inside expression):
syms x(t) y(t) z(t) c
z(t) = cos(c + x(t)) + y(t)^2;
dzdt = diff(z, t)
dzdt(t) =
2*y(t)*diff(y(t), t) - sin(c + x(t))*diff(x(t), t)
One of these should work for you.

### Categories

Find more on Common Operations in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!