Derivative of a symbolic function with multiple dependent variables
3 views (last 30 days)
Show older comments
Gabriele Porcelli
on 2 Mar 2020
Commented: Gabriele Porcelli
on 7 Mar 2020
Hello everybody. I'm facing this problem. I have a variable q(t) time dependent. I have to derive it in MatLab and I want to substitute numerical values to q(t), qd(t) but if I do that, as one can expect, the derivative of a number is 0 and then my function is constantly equal to 0. i write here an example:
syms q(t)
f = 2*q^2;
fd = diff(f,t)
subs(fd,q,5).
The result is 4*q(t)*diff(q(t), t).
So fd is function of q and qd and I want to substitute both with numerical numbers. Do you know any solution?
0 Comments
Accepted Answer
Sai Sri Pathuri
on 5 Mar 2020
If you want to substitute values for q(t) and dq(t), you may fisrt substitute the value for dq(t) followed by the value for q(t). Let the value to be substituted for dq(t) be 2.
syms q(t)
f = 2*q^2;
fd = diff(f,t)
a = subs(fd,diff(q(t),t),2)
which gives an output
fd(t) = 4*q(t)*diff(q(t), t)
a(t) = 8*q(t)
Now, you may substitute the value of q(t) in a(t)
subs(a(t),q(t),5)
to get the ouput as
ans = 40
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox 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!