solve nonlinear Lagrange equation
조회 수: 6 (최근 30일)
이전 댓글 표시
Is it possible to derive q''[t] in this equation in matlab code? (not Simulink)
q''[t] = M(q[t])^-1*(T-c(q[t],q'[t])-k*q[t])
where q'[t] is the integral of q''[t], and q[t] is the integral of q'[t]. M and c are Matrices which are nonlinear functions of q[t] and q'[t]. I have done this in Simulink. But, wonder if it is possible with codes in m-file too?
Thanks for any help
I'll type my code here to make it clear:
function [M,C,G] = M(q1,q2)
a = m1*(l1/2)^2 + m2*l1^2 + I1;
b = m2*l1*l2*cos(q1-q2)/2;
c = m2*l1*l2*cos(q1-q2)/2;
d = m2*(l2/2)^2 + I2;
M = [a b;c d];
a2 = m1*g*l1*cos(q1)/2 + m2*g*l1*cos(q1);
b2 = m2*g*l2*cos(q2)/2;
G = [a2;b2];
end
function cqdot = cqdot(qdot1,qdot2,q1,q2,theta1ref,theta2ref)
a1 = 0;
b1 = m2*l1*l2*qdot2*sin(q1-q2)/2;
c1 = -m2*l1*l2*qdot1*sin(q1-q2)/2;
d1 = 0;
C = [a1 b1;c1 d1];
qdot = [qdot1;qdot2];
cqdot = C*qdot;
f1 = Kp1 * (theta1ref-q1) - Kd1* (qdot1) ;
f2 = Kp2 * (theta2ref-q2) - Kd1* (qdot2) ;
Fhat = [f1,f2];
F = M*Fhat;
end
function [qdotdot,qdot,q] = fun(M,cqdot,G,F)
qdotdot = inv(M)*(-cqdot-G+F);
qdot = comtrapz(qdotdot,t);
q = comtrapz(qdot,t);
end
where m1, m2, l1,l2,I1,I2, g, kp1,kp2, kd1,kd2 are all defined values. and theta1ref and theta2ref are vectors which are treated as input signals.
This way does not work. But with Matlab Function in Simulink it works properly.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!