What is wrong with my differentiation of function of phi(t)?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Adam Chelchowski
le 11 Fév 2021
Commenté : Adam Chelchowski
le 11 Fév 2021
I need to derive equations of motion using Lagrange' s method. I have xi, yi: i=0,1,2 coordinates with respect to phi(t), q1(t), q2(t), which are angles. When I have e.g. x_0 as a function of above mentioned coordinates, I differentiate it with respect to time t, then I calculate the energy I need to apply to EL equations and then, having: L=T-V when I need to differentiate dL/d(phi'(t)) using: diff(L,diff(phi(t),t)) I constantly get a messaege: ' Arguments, except for the first, must not be symbolic functions.' which appears only after I want to differentiate above L with respect to phi'(t). If I do not place the L differentiation, everything is okay. I changed the code so that I have phi(t) and dtPhi(t) which are both syms, but it does not solve the problem, I need to differentiate phi(t) w.r.t. t and then L w.r.t phi'(t). Summing up, I need to differentiate Function L with respect to phi'(t) and in 'syms' I only placed phi(t). Is it because in the second differentiation MATLAB uses diff(phi,t) as a function?
I have sth like this:
syms fi(t) q1(t) q2(t) l0 l1 l2 b0 b1 b2 m0 m1 m2 M i0 i1 i2 dtfi(t) dtq1(t) dtq2(t)
x0(t)=sin(fi)*(b1*sin(q1)+b0)*m1/M+(l1*sin(q1)+b2*sin(q1+q2)+b0)*m2/M-cos(fi)*(b1*cos(q1)+l0)*m1/M+(l1*cos(q1)+l0+b2*cos(q1+q2))*m2/M;
dt_x0=diff(x0,1);
y0(t)=-cos(fi)*(b1*sin(q1)+b0)*m1/M+(l1*sin(q1)+b2*sin(q1+q2)+b0)*m2/M-sin(fi)*(b1*cos(q1)+l0)*m1/M+(l1*cos(q1)+l0+b2*cos(q1+q2))*m2/M;
dt_y0=diff(y0,1);
x1(t)=cos(fi)*((b1*cos(q1)+l0)*(1-m1/M)-(l1*cos(q1)+b2*cos(q1+q2)+l0)*m2/M)-sin(fi)*((b1*sin(q1)+b0)*(1-m1/M)-(l1*sin(q1)+b0+b2*sin(q1+q2))*m2/M);
dt_x1=diff(x1,1);
y1(t)=sin(fi)*((b1*cos(q1)+l0)*(1-m1/M)-(l1*cos(q1)+b2*cos(q1+q2)+l0)*m2/M)+cos(fi)*((b1*sin(q1)+b0)*(1-m1/M)-(l1*sin(q1)+b0+b2*sin(q1+q2))*m2/M);
dt_y1=diff(y1,1);
x2(t)=cos(fi)*(l1*cos(q1)+b2*cos(q1+q2)+l0)-m1/M*(b1*cos(q1)+l0)-cos(fi)*(l1*cos(q1)+b2*cos(q1+q2)+l0)*m2/M-sin(fi)*(l1*sin(q1)+b0+b2*sin(q1+q2)-m1/M*(b1*sin(q1)+b0))-sin(fi)*(l1*sin(q1)+b2*sin(q1+q2)+b0)*m2/M;
dt_x2=diff(x2,1);
y2(t)=sin(fi)*(l1*cos(q1)+b2*cos(q1+q2)+l0)-m1/M*(b1*cos(q1)+l0)-sin(fi)*(l1*cos(q1)+b2*cos(q1+q2)+l0)*m2/M+cos(fi)*(l1*sin(q1)+b0+b2*sin(q1+q2)-m1/M*(b1*sin(q1)+b0))-cos(fi)*(l1*sin(q1)+b2*sin(q1+q2)+b0)*m2/M;
dt_y2=diff(y2,1);
dt_fi=diff(fi,1);
%dt_fi=diff(fi,t);
%Kinetic energy and also L=T-V, when V==0
L=1/2*m0*(diff(x0,1)^2+diff(y0,1)^2)+1/2*(i0+m0*(x0(t)^2+y0(t)^2))*diff(fi,1)^2+1/2*m1*(diff(x1,1)^2+diff(y1,1)^2)+1/2*(i1+m1*(x1(t)^2+y1(t)^2))*(diff(fi,1)+diff(q1,1))^2+1/2*m2*(diff(x2,1)^2+diff(y2,1)^2)+1/2*(i2+m2*(x2(t)^2+y2(t)^2))*(diff(fi,1)+diff(q1,1)+diff(q2,1))^2;
% Angular momentum
K=m0*(x0*diff(y0,1)-y0*diff(x0,1))+i0*diff(fi,1)+m1*(x1*diff(y1,1)-y1*diff(x1,1))+i1*(diff(fi,1)+diff(q1,1))+m2*(x2*diff(y2,1)-y2*diff(x2,1))+i2*(diff(fi,1)+diff(q1,1)+diff(q2,1));
%Lagrange II
%d/dt(dL/dq*_i)-dL/dq_i=0
%q_i: fi, q1, q2
%q*_i:dt_fi, dt_q1, dt_q2
%L=T-V=T
D11=diff(L, diff(fi,t)); %Here' s the problem, an error occurs; I need sth to differentiate it with respect to diff(fi,t)
D12=diff(D11,t);
D13=functionalDerivative(L, fi);
0 commentaires
Réponse acceptée
Paul
le 11 Fév 2021
I think what you want is to substitute a variable for diff(fi,t), differenitate wrt to that variable, and substitute back.
>> syms fiprime
>> L(t) = t^2 + t^3*diff(fi(t),t)^2; % example
>> D11 = subs(diff(subs(L(t),diff(fi(t),t),fiprime),fiprime),fiprime,diff(fi(t),t))
D11 =
2*t^3*diff(fi(t), t)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Equation Solving dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!