Derivative of a symbolic function with multiple dependent variables

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Sai Sri Pathuri
Sai Sri Pathuri am 5 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by