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 gT0 = 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)
Best Answer