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

조회 수: 12 (최근 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에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by