You are on page 1of 4

Lagrange Equations Using MATLAB 1.

Kinetic and Potential Energy Equations

The equation for the kinetic energy is:

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

This is programmed in MATLAB as:


c
x

k/2 K k/2 syms m M g L cvv cth k K IG a zg zgdot zgdotdot z zdot


zdotdot v vdot vdotdot th thdot thdotdot real
m

cv/2 cv/2 syms x1 x2 x3 x4 u real

% 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;

The equation for the potential energy is:


The motion of a building subjected to earthquake excitation is to be
studied using the model shown above. Assume the foundation mass, m, 1 1
k ( z - z g ) + Kq 2 + Mga cos q
2
to be a lumped mass. V= (2)
2 2
Goals: Use Matlab/Simulink to (i) derive the equations of motion for the
which is programmed in MATLAB as:
system given above using Lagrange Equations, and (ii) to simulate the
nonlinear and linearized equations of motion for the system and compare % Potential Energy
results. V = 0.5*k*(z-zg)^2 + 0.5*K*th^2 + M*g*a*cos(th);

2. Nonconservative Forces

The non-conservative forces are found as:

d WNC = -cv ( z&- z&g ) d z - ( cq q&) dq (3)


and coded into MATLAB as:

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);

Each term in Eq. (4) can be coded in MATLAB as follows:

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

appropriate equations from which to derive the state space representation


of this system. The code to achieve all of this is:
(
To find f v v, v& )
, q , q&, &
z&
g ( , q ,q&, &
and fq v, v& )
z&
g , the two equations,

% Rewrite the EOM using relative coordinates (i.e., &and q&


Eqv = 0 and Eqq = 0 , are solved for v& &. In MATLAB, this is
% v = z - zg) achieved by:
z = v + zg;
zdot = vdot + zgdot;
% Solve for vdotdot and thdotdot for the state space
zdotdot = vdotdot + zgdotdot; formulation.
Sol = solve(Eqv1,Eqth1,'vdotdot,thdotdot');
%The equation of motion for v (Eqv1=0) Sol.vdotdot = simple(Sol.vdotdot);
Eqv1 = simple(subs(eqz));
Sol.thdotdot = simple(Sol.thdotdot);
%The equation of motion for th (Eqth1=0)
Eqth1 = simple(subs(eqth));
Finally, we substitute into these solutions the names of the state (x1, x2, x3,
fprintf('\n%s\n','The EOM in relative coordinates.') and x4) and the input ( u ).
pretty(Eqv1)
pretty(Eqth1) fv=subs(Sol.vdotdot,{v,vdot,th,thdot,zgdotdot},
{x1,x2,x3,x4,u})
For future reference, let us denote the equations found above as:
fth=subs(Sol.thdotdot,{ v,vdot,th,thdot,zgdotdot},
{x1,x2,x3,x4,u})
Eqv = Eqv1 and Eqq = Eqth1

5. State Space Formulation 6. Linearized State Space Representation

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

The system must be linearized with respect to an operating point,


typically a state of either stable or unstable equilibrium. In this case, we
will linearize the system about its rest position.

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

Each terms can be calculated as follows

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})

The system is now in a linear state-space form, and can be used in


Simulink models.

You might also like