Professional Documents
Culture Documents
Lagrange Equations Using MATLAB: 1. Kinetic and Potential Energy Equations
Lagrange Equations Using MATLAB: 1. Kinetic and Potential Energy Equations
1 2 1 1
M, IG
T= mz& + M ( x&G2 + y&G2 ) + I Gq&2 (1)
L
2 2 2
where
x&G = z&+ aq&cos q , y&G = -aq&sin q
g
G
a
y
% Kinetic Energy
z
xgdot = zdot+a*cos(th)*thdot;
zg ygdot = -a*sin(th)*thdot;
T = 0.5*m*zdot^2 + 0.5*M*(xgdot^2+ygdot^2)
+ 0.5*IG*thdot^2;
2. Nonconservative Forces
1
T pTpzdot = diff(T,zdot);
% Nonconservative Forces
Pz = -cvv*(zdot-zgdot); z&
Pth = -cth*thdot; d T ddtpTpzdot = diff(pTpzdot,z)*zdot + ...
& diff(pTpzdot,zdot)*zdotdot + ...
dt z diff(pTpzdot,th)*thdot + ...
diff(pTpzdot,thdot)*thdotdot;
3. Lagranges Equations
T pTpz = diff(T,z);
The next step is to perform the appropriate calculations to find the z
Lagrange Equations, which are given by:
V pVpz = diff(V,z);
d T T V z
&- + = Pz (4)
dt z z z Each term in Eq. (5) is coded, using MATLAB, as shown below:
and
T pTpthdot = diff(T,thdot);
d T T V q&
&- + = Pq (5) d T
q
dt q q &
ddtpTpthdot = diff(pTpthdot,z)*zdot + ...
dt q diff(pTpthdot,zdot)*zdotdot + ...
diff(pTpthdot,th)*thdot + ...
The chain rule must be used to evaluate the first integral in Lagranges diff(pTpthdot,thdot)*thdotdot;
Equations using Matlab, i.e.:
T pTpth = diff(T,th);
q
d T N T dq j T dq&j
V
= +
pVpth = diff(V,th);
(6)
q&i j =1
dt q&i dt
q j q&j
q&i dt q
Combining these terms together yields the two equations of motion:
d T
As an example, &is written as:
dt z % The equation of motion for "z" (eqz = 0)
eqz = simple(ddtpTpzdot - pTpz + pVpz - Pz);
d T = T dz + T dz&+ T dq + T dq& % The equation of motion for "th" (eqth = 0)
dt z& z
z&dt z&
z&dt q
z&dt q&
z&dt eqth = simple(ddtpTpthdot - pTpth + pVpth - Pth);
2
4. Equations of Motion in Relative x&1 v&
v& x3
Coordinates x& v&
dx 2 & v
f v , &
v , q ,(q&, &
&
z g )
f v ( x1 , x2 , x3 , x4 , u ) (7)
= = &= =
The equations of motion are written with respect to the absolute dt x&3 q q& x4
coordinates. To get the equations of motion in relative coordinates, we
x&4
q&
&
f v , &
v , q ,(q&, &
z& fq ( x1 , x2 , x3 , x4 , u )
)
substitute z = v + z g into the EOMs. The result will give us the q g
To simulate the system response, the EOM must be put into state space The linearized state space representation is given by:
form. If we define our state vector as:
x&= Ax + Bu
{ } (8)
'
x = v v& q q& = { x1 x4 }
'
x2 x3
Start from the nonlinear equations found in Section 5, f v = 0 and fq = 0
then the nonlinear state space representation as follows: . A Taylor Series approximation will be used to linearize the equations of
motion.
3
Taylor Series Approximation
f i f i
(x - xj ) + (u -uj)
n m
f i ( x1 , , xn , u1 , , u m ) = x j j
j =1 j x =x j =1 u j
j j u j =u j
x1 , x2 , x3 , x4 , u = 0,0,0,0,0
Applying a Taylor Series approximation, you will find that the state-space
can be written in a form as below.
0 1 0 0 0
x 1 f v f v f v f v x1 f v
x
2 = x1 x2 x3 x4 x2 u
+ u
x 3 0 0 0 1 x3 0
fq fq fq fq fq
x 4 x x
1 x2 x3 x4 4 u
pfvpx1=subs(diff(fv,x1),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfvpx2=subs(diff(fv,x2),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfvpx3=subs(diff(fv,x3),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfvpx4=subs(diff(fv,x4),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfvpu=subs(diff(fv,u),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfthpx1=subs(diff(fth,x1),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfthpx2=subs(diff(fth,x2),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfthpx3=subs(diff(fth,x3),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfthpx4=subs(diff(fth,x4),{x1,x2,x3,x4,u},{0,0,0,0,0})
pfthpu=subs(diff(fth,u),{x1,x2,x3,x4,u},{0,0,0,0,0})