Getting error: Second argument must be a variable or a nonnegative integer specifying the number of differentiations.
Ältere Kommentare anzeigen
I am trying to symbolically obtain the Euler-Lagrange equations, but I keep getting the "Second argument must be a variable or a nonnegative integer specifying the number of differentiations" error. It occurs with the first term of the equation (dL/dx_dot). I don't what I am doing wrong. Any help is appreciated. Thanks.
syms x(t) theta1(t) theta2(t) F(t) m0 m1 m2 I1 I2 L1 L2 g
T0 = 0.5*m0*diff(x(t),t)^2; %Kinetic energy of mass
T1 = 0.5*m1*((diff(x(t),t)+0.5*L1*diff(theta1(t),t)*cos(theta1(t)))^2+(L1*diff(theta1(t),t)*sin(theta1(t)))^2)+0.5*I1*diff(theta1(t),t)^2; %Kinetic energy of pendulum 1
T2 = 0.5*m2*((diff(x(t),t)+L1*diff(theta1(t),t)*cos(theta1(t))+0.5*L2*diff(theta2(t),t)*cos(theta2(t)))^2+(L1*diff(theta1(t),t)*sin(theta1(t))+0.5*L2*diff(theta2(t),t)*sin(theta2(t)))^2)+0.5*I2*diff(theta2(t),t)^2; %Kinetic energy of pendulum 2
T = T0+T1+T2; % Total kinetic energy
U0 = 0; %Potential energy of mass
U1 = m1*g*0.5*L1*cos(theta1(t)); %Potential energy of pendulum 1
U2 = m2*g*(L1*cos(theta2(t))+0.5*L2*cos(theta2(t))); %Potential energy of pendulum 2
U = U0+U1+U2; %Total potential energy
L = T-U; %Lagrangian of system
dL_dx_dot = diff(L,diff(x(t),t));
dL_dx = diff(L,x);
diff(dL_dx_dot,t) - dL_dx == F(t)
3 Kommentare
Star Strider
am 19 Okt. 2020
In R2020b, I get:
ans(t) =
2*F(t) + L1*m1*sin(theta1(t))*diff(theta1(t), t)^2 + 2*L1*m2*sin(theta1(t))*diff(theta1(t), t)^2 + L2*m2*sin(theta2(t))*diff(theta2(t), t)^2 == 2*m0*diff(x(t), t, t) + 2*m1*diff(x(t), t, t) + 2*m2*diff(x(t), t, t) + L1*m1*cos(theta1(t))*diff(theta1(t), t, t) + 2*L1*m2*cos(theta1(t))*diff(theta1(t), t, t) + L2*m2*cos(theta2(t))*diff(theta2(t), t, t)
and no errors.
Missael Hernandez
am 19 Okt. 2020
Walter Roberson
am 19 Okt. 2020
Interesting, I did not notice that in R2020b they improved this.
My answer below applies up to R2020a.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Assembly finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!