Getting error: Second argument must be a variable or a nonnegative integer specifying the number of differentiations.
101 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Missael Hernandez
il 19 Ott 2020
Commentato: Walter Roberson
il 19 Ott 2020
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 Commenti
Walter Roberson
il 19 Ott 2020
Interesting, I did not notice that in R2020b they improved this.
My answer below applies up to R2020a.
Risposta accettata
Walter Roberson
il 19 Ott 2020
It is not possible to differentiate with respect to a function.
You have to make a substitution and hope that the system remains valid.
syms Dx;
dL_dx_dot = subs(diff( subs(L,diff(x(t),t),Dx), Dx), Dx, diff(x(t),t))
This is not guaranteed to be valid in general! In the past I have posted systems that this kind of manipulation is not valid for. It depends upon the rest of the equation being independent of the function whose derivative is being taken, and that is not always the case.
The situation is sort of like making a substitution assuming that you are not dividing by zero -- the substitution would often work, but there are cases where you accidentally introduce nonsense answers when you make such a substitution.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Assembly in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!