How do you take the partial derivative of a function relative to theta dot

19 vues (au cours des 30 derniers jours)
Need to take the partial derivative of l with respect to theta 1 dot
clear; clc;
syms theta1(t) theta2(t) r1 r2 m1 m2 g
%theta1dot=diff(theta1)
%theta2dot=diff(theta2)
x1 = r1*sin(theta1);
y1 = -r1*cos(theta1);
x2 = x1+r2*sin(theta2+theta1);
y2 = y1-r2*cos(theta2+theta1);
x1dot=diff(x1)
y1dot=diff(y1);
x2dot=diff(x2);
y2dot=diff(y2);
pe=m1*g*y1+m2*g*y2;
ke=1/2*m1*(x1dot^2+y1dot^2)+1/2*m2*(x2dot^2+y2dot^2);
l=ke-pe
diff(l,theta1)

Réponse acceptée

Andreas Apostolatos
Andreas Apostolatos le 29 Nov 2022
Modifié(e) : Andreas Apostolatos le 29 Nov 2022
Hi Cason,
You can achieve this workflow by substituting the symbolic expression diff(theta1) with a symbolic variable theta1dot in expression l(t), take the derivative of that expression with respect to theta1dot and finally substitute back symbolic variable theta1dot with diff(theta1) in the resulting expression, namely,
syms theta1dot
subs(diff(subs(l(t), diff(theta1(t)), theta1dot), theta1dot), theta1dot, diff(theta1(t)))
I have cascaded all underlying operations, but feel free to expand them in multiple lines of code to get a more readable version of the latter one. For more information on function subs, please read the corresponding documentation page,
I hope this helps.
Kind regards
Andreas

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by