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

18 次查看(过去 30 天)
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)

采纳的回答

Andreas Apostolatos
Andreas Apostolatos 2022-11-29
编辑:Andreas Apostolatos 2022-11-29
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by