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

18 ビュー (過去 30 日間)
Cason Cox
Cason Cox 2022 年 11 月 29 日
編集済み: Andreas Apostolatos 2022 年 11 月 29 日
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 Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by