Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

23
Generalized Coordinates, Lagrange’s Equations, and Constraints CEE 541. Structural Dynamics Department of Civil and Environmental Engineering Duke University Henri P. Gavin Fall, 2016 1 Cartesian Coordinates and Generalized Coordinates The set of coordinates used to describe the motion of a dynamic system is not unique. For example, consider an elastic pendulum (a mass on the end of a spring). The position of the mass at any point in time may be expressed in Cartesian coordinates (x(t),y(t)) or in terms of the angle of the pendulum and the stretch of the spring (θ(t),u(t)). Of course, these two coordinate systems are related. For Cartesian coordinates centered at the pivot point, θ u y = -(l+u)cos y x = (l+u)sin l x θ θ K g M x(t) = (l + u(t)) sin θ(t) (1) y(t) = -(l + u(t)) cos θ(t) (2) where l is the un-stretched length of the spring. Let’s define r(t)= r 1 (t) r 2 (t) = x(θ(t),u(t)) y(θ(t),u(t)) = (l + u(t)) sin θ(t) -(l + u(t)) cos θ(t) (3) and q(t)= q 1 (t) q 2 (t) = θ(t) u(t) (4) so that r(t) is a function of q(t). The potential energy, V , may be expressed in terms of r or in terms of q. In Cartesian coordinates, the velocities are ˙ r(t)= ˙ r 1 (t) ˙ r 2 (t) = ˙ u(t) sin θ(t)+(l + u(t)) cos θ(t) ˙ θ(t) - ˙ u(t) cos θ(t)+(l + u(t)) sin θ(t) ˙ θ(t) (5) So, in general, Cartesian velocities ˙ r(t) can be a function of both the velocity and position of some other coordinates ( ˙ q(t) and q(t)). Such coordinates q are called generalized coordinates. The kinetic energy, T , may be expressed in terms of either ˙ r or, more generally, in terms of ˙ q and q. Small changes (or variations) in the rectangular coordinates, (δx, δy) consistent with all displacement constraints, can be found from variations in the generalized coordinates (δθ, δu). δx = ∂x ∂θ δθ + ∂x ∂u δu =(l + u(t)) cos θ(t)δθ + sin θ(t)δu (6) δy = ∂y ∂θ δθ + ∂y ∂u δu =(l + u(t)) sin θ(t)δθ - cos θ(t)δu (7)

Transcript of Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Page 1: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates, Lagrange’s Equations, and ConstraintsCEE 541. Structural Dynamics

Department of Civil and Environmental EngineeringDuke University

Henri P. GavinFall, 2016

1 Cartesian Coordinates and Generalized CoordinatesThe set of coordinates used to describe the motion of a dynamic system is not unique.

For example, consider an elastic pendulum (a mass on the end of a spring). The position ofthe mass at any point in time may be expressed in Cartesian coordinates (x(t), y(t)) or interms of the angle of the pendulum and the stretch of the spring (θ(t), u(t)). Of course, thesetwo coordinate systems are related. For Cartesian coordinates centered at the pivot point,

θ

u

y =

−(l

+u

)cos

y

x = (l+u)sin

l

x

θ

θ

K

gM

x(t) = (l + u(t)) sin θ(t) (1)y(t) = −(l + u(t)) cos θ(t) (2)

where l is the un-stretched length of the spring. Let’s define

r(t) =[r1(t)r2(t)

]=[x(θ(t), u(t))y(θ(t), u(t))

]=[

(l + u(t)) sin θ(t)−(l + u(t)) cos θ(t)

](3)

andq(t) =

[q1(t)q2(t)

]=[θ(t)u(t)

](4)

so that r(t) is a function of q(t).The potential energy, V , may be expressed in terms of r or in terms of q.

In Cartesian coordinates, the velocities are

r(t) =[r1(t)r2(t)

]=[

u(t) sin θ(t) + (l + u(t)) cos θ(t)θ(t)−u(t) cos θ(t) + (l + u(t)) sin θ(t)θ(t)

](5)

So, in general, Cartesian velocities r(t) can be a function of both the velocity and position ofsome other coordinates (q(t) and q(t)). Such coordinates q are called generalized coordinates.The kinetic energy, T , may be expressed in terms of either r or, more generally, in terms ofq and q.

Small changes (or variations) in the rectangular coordinates, (δx, δy) consistent with alldisplacement constraints, can be found from variations in the generalized coordinates (δθ, δu).

δx = ∂x

∂θδθ + ∂x

∂uδu = (l + u(t)) cos θ(t)δθ + sin θ(t)δu (6)

δy = ∂y

∂θδθ + ∂y

∂uδu = (l + u(t)) sin θ(t)δθ − cos θ(t)δu (7)

Page 2: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

2 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

2 Principle of Virtual DisplacementsVirtual displacements δri are any displacements consistent with the constraints of the

system. The principle of virtual displacements1 says that the work of real external forcesthrough virtual external displacements equals the work of the real internal forces arisingfrom the real external forces through virtual internal displacements consistent with the realexternal displacements. In system described by n coordinates ri, with n internal inertialforces Mri(t), potential energy V (r), and n external forces pi collocated with coordinates ri,the principle of virtual dispalcements says,

n∑i=1

(Mri + ∂V

∂ri

)δri =

n∑i=1

(pi(t)) δri (8)

3 Minimum Total Potential EnergyThe total potential energy, Π, is defined as the internal potential energy, V , minus the

potential energy of external forces2. In terms of the r (Cartesian) coordinate system andn forces fi collocated with the n displacement coordinates, ri, the total potential energy isgiven by equation (9).

Π(r) = V (r)−n∑

i=1firi . (9)

The principle of minimum total potential energy states that the total potential energy isminimized in a condition of equilibrium. Minimizing the total potential energy is the sameas setting the variation of the total potential energy to zero. For any arbitrary set of “varia-tional” displacements δri(t), consistent with displacement constraints,

minr

Π(r)⇒ δΠ(r) = 0⇔n∑

i=1

∂Π∂ri

δri = 0⇔n∑

i=1

∂V

∂ri

δri −n∑

i=1fi δri = 0 , (10)

In a dynamic situation, the forces fi can include inertial forces, damping forces, and externalloads. For example,

fi(t) = −Mri(t) + pi(t) , (11)where pi is an external force collocated with the displacement coordinate ri. Substitutingequation (11) into equation (10), and rearranging slightly, results in the d’Alembert-Lagrangeequations, the same as equation (8) found from the principle of virtual displacements,

n∑i=1

(Mri(t) + ∂V

∂ri

− pi(t))δri = 0 . (12)

In equations (8) and (12) the virtual displacements (i.e., the variations) δri must be arbitraryand independent of one another; these equations must hold for each coordinate ri individually.

Mri(t) + ∂V

∂ri

− pi(t) = 0 . (13)1d’Alembert, J-B le R, 17432In solid mechanics, internal strain energy is conventionally assigned the variable U , whereas the potential

energy of external forces is conventionally assigned the variable V . In Lagrange’s equations potential energyis assigned the variable V and kinetic energy is denoted by T .

CC BY-NC-ND HP Gavin

Page 3: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 3

4 Derivation of Lagrange’s equations from “f = ma”

For many problems equation (13) is enough to determine equations of motion. However,in coordinate systems where the kinetic energy depends on the position and velocity ofsome generalized coordinates, q(t) and q(t), expressions for inertial forces become morecomplicated.

The first goal, then, is to relate the work of inertial forces (∑i Mri δri) to the kineticenergy in terms of a set of generalized coordinates. To do this requires a change of coordinatesfrom variations in n Cartesian coordinates δr to variations in m generalized coordinates δq,

δri =m∑

j=1

∂ri

∂qj

δqj =m∑

j=1

∂ri

∂qj

δqj and d

dtδri = δri =

m∑j=1

∂ri

∂qj

δqj . (14)

Now, consider the kinetic energy of a constant mass M . The kinetic energy in terms ofvelocities in Cartesian coordinates is given by T (r) = 1

2M(r21 + r2

2), and

∂T

∂ri

δri = Mri δri . (15)

Applying the product and chain rules of calculus to equation (15),

d

dt

(∂T

∂ri

δri

)= Mri δri +Mri

d

dtδri (16)

d

dt

∂T∂ri

m∑j=1

∂ri

∂qj

δqj

= Mri δri + ∂T

∂ri

δri (17)

Mri δri = d

dt

∂T∂ri

m∑j=1

∂ri

∂qj

δqj

− ∂T

∂ri

m∑j=1

∂ri

∂qj

δqj . (18)

Equation (18) is a step to getting the work of inertial forces (∑i Mri δri) in terms of a set ofgeneralized coordinates qj. Next, changing the derivatives of the potential energy from ri toqj,

∂V

∂ri

δri =m∑

j=1

∂V

∂qj

∂qj

∂ri

∂ri

∂qj

δqj . (19)

Finally, expressing the work of external forces pi in terms of the new coordinates qj,

n∑i=1

pi(t) δri =n∑

i=1pi(t)

m∑j=1

∂ri

∂qj

δqj =m∑

j=1

n∑i=1

pi(t)∂ri

∂qj

δqj =m∑

j=1Qj(t) δqj , (20)

where Qj(t) are called generalized forces. Substituting equations (18), (19) and (20) intoequation (12), rearranging the order of the summations, factoring out the common δqj,canceling the ∂ri and ∂ri terms, and eliminating the sum over i, leaves the equation in terms

CC BY-NC-ND HP Gavin

Page 4: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

4 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

of qj and qj,

n∑i=1

ddt

∂T∂ri

m∑j=1

∂ri

∂qj

δqj

− ∂T

∂ri

m∑j=1

∂ri

∂qj

δqj +m∑

j=1

∂V

∂qj

∂qj

∂ri

∂ri

∂qj

δqj − pi(t)m∑

j=1

∂ri

∂qj

δqj

= 0

m∑j=1

n∑i=1

[d

dt

(∂T

∂ri

∂ri

∂qj

)− ∂T

∂ri

∂ri

∂qj

+ ∂V

∂qj

∂qj

∂ri

∂ri

∂qj

− pi∂ri

∂qj

]δqj = 0

m∑j=1

[d

dt

(∂T

∂qj

)− ∂T

∂qj

+ ∂V

∂qj

−Qj

]δqj = 0

The variations δqj must be arbitrary and independent of one another; this equation musthold for each generalized coordinate qj individually. Removing the summation over j andcanceling out the common δqj factor results in Lagrange’s equations,3

d

dt

(∂T

∂qj

)− ∂T

∂qj

+ ∂V

∂qj

−Qj = 0 (21)

are which are applicable in any coordinate system, Cartesian or not.

5 The Lagrangian

Lagrange’s equations may be expressed more compactly in terms of the Lagrangian ofthe energies,

L(q, q, t) ≡ T (q, q, t)− V (q, t) (22)

Since the potential energy V depends only on the positions, q, and not on the velocities, q,Lagrange’s equations may be written,

d

dt

(∂L

∂qj

)− ∂L

∂qj

−Qj = 0 (23)

3Lagrange, J.L., Mecanique analytique, Mm Ve Courcier, 1811.

CC BY-NC-ND HP Gavin

Page 5: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 5

6 Explanation of Lagrange’s equations in terms of Hamilton’s principle

Define a Lagrangian of kinetic and potential energies

L(q, q, t) ≡ T (q, q, t)− V (q, t) (24)

and define an action potential functional

S[q(t)] =∫ t2

t1L(q, q, t) dt (25)

with end points q1 = q(t1) and q2 = q(t2). Consider the true path of q(t) from t1 to t2 anda variation δq(t) such that δq(t1) = 0 and δq(t2) = 0.

Hamilton’s principle:4

The solution q(t) is an extremum of the action potential S[q(t)]⇐⇒ δS[q(t)] = 0⇐⇒

∫ t2

t1δL(q, q, t) dt = 0

Substituting the Lagrangian into Hamilton’s principle,∫ t2

t1

{∑i

[∂T

∂qi

δqi + ∂T

∂qi

δqi −∂V

∂qi

δqi

]}dt = 0

We wish to factor out the independent variations δqi, however the first term contains thevariation of the derivative, δqi. If the conditions for admissible variations in position δqfully specify the conditions for admissible variations in velocity δq, the variation and thedifferentiation can be transposed,

d

dtδqi = δqi, (26)

and we can integrate the first term by parts,

∫ t2

t1

∂T

∂qi

δqi =[∂T

∂qi

δqi

]t2

t1

−∫ t2

t1

d

dt

(∂T

∂qi

)δqi dt

Since δq(t1) = 0 and δq(t2) = 0,∫ t2

t1

{∑i

[− d

dt

(∂T

∂qi

)δqi + ∂T

∂qi

δqi −∂V

∂qi

δqi

]}dt = 0

The variations δqi must be arbitrary, so the term within the square brackets must be zerofor all i.

d

dt

(∂T

∂qi

)− ∂T

∂qi

+ ∂V

∂qi

= 0.

4Hamilton, W.R., “On a General Method in Dynamics,” Phil. Trans. of the Royal Society Part II (1834)pp. 247-308; Part I (1835) pp. 95-144

CC BY-NC-ND HP Gavin

Page 6: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

6 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

7 A Little History

I_Newton.jpg JR_dAlembert.jpgJL_Lagrange.jpgJCF_Gauss.jpgWR_Hamilton.jpg

Sir Jean-Baptiste Carl WilliamIsaac le Rond Joseph-Louis Fredrich Rowan

Newton d’Alembert Lagrange Gauss Hamilton

1642-1727 1717-1783 1736-1813 1777-1855 1805-1865

Second d’Alembert’s Mechanique Gauss’s Hamilton’sLaw Principle Analytique Principle Principle1687 1743 1788 1829 1834-1835

fi dt = d(mivi)∑(fi −miai)δri = 0

ddt

∂L∂qi− ∂L

∂qi= Qi

G = 12(q − a)TM(q − a)

δG = 0

S =∫ t2

t1L(q, q, t)dt

δS = 0

CC BY-NC-ND HP Gavin

Page 7: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 7

8 Example: an elastic pendulum

For an elastic pendulum (a mass swinging on the end of a spring), it is much easier toexpress the kinetic energy and the potential energy in terms of θ and u than x and y.

T (θ, u, θ, u) = 12M((l + u)θ)2 + 1

2Mu2 (27)

V (θ, u) = Mg(l − (l + u) cos θ) + 12Ku

2 (28)

Lagrange’s equations require the following derivatives (where q1 = θ and q2 = u):

d

dt

∂T

∂q1= d

dt

∂T

∂θ= d

dt(M(l + u)2θ) = M(2(l + u)uθ + (l + u)2θ) (29)

∂T

∂q1= ∂T

∂θ= 0 (30)

∂V

∂q1= ∂V

∂θ= Mg(l + u) sin θ (31)

d

dt

∂T

∂q2= d

dt

∂T

∂u= d

dtMu = Mu (32)

∂T

∂q2= ∂T

∂u= M(l + u)θ2 (33)

∂V

∂q2= ∂V

∂u= Ku−Mg cos θ (34)

Substituting these derivatives into Lagrange’s equations for q1 gives

M(2(l + u)uθ + (l + u)2θ) +Mg(l + u) sin θ = 0 . (35)

Substituting these derivatives into Lagrange’s equations for q2 gives

Mu−M(l + u)θ2 +Ku−Mg cos θ = 0 . (36)

These last two equations represent a pair of coupled nonlinear ordinary differential equationsdescribing the unconstrained motion of an elastic pendulum. They may be written in matrixform as [

M(l + u)2 00 M

] [θu

]=[−Mg(l + u) sin θ −M2(l + u)uθM(l + u)θ2 −Ku+Mg cos θ

](37)

orM(q(t), t) q(t) = Q(q(t), q(t), t) (38)

As can be seen, the inertial terms (involving mass) are more complicated than justMr, and can involve position, velocity, and acceleration of the generalized coordinates. Bycarefully relating forces in Cartisian coordinates to those in generalized coordinates throughfree-body diagrams the same equations of motion may be derived, but doing so with La-grange’s equations is often more straight-forward once the kinetic and potential energies arederived.

CC BY-NC-ND HP Gavin

Page 8: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

8 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

9 Maple software to compute derivatives for Lagrange’s equations

9.1 A forced spring-mass-damper oscillator

Consider a forced mass-spring-damper oscillator . . . basically the same as the elasticpendulum with just the u(t) coordinate, (without the θ coordinate), but with some linearviscous damping in parallel with the spring, and external forcing f(t), collocated with thedisplacement u(t).

T (u, u) = 12Mu(t)2

V (u) = 12Ku(t)2

p(u, u) δu = −cu(t) δu+ f(t) δu

where (p δu) is the work of real non-conservative forces through a virtual displacement δu, inwhich the damping force is cu and the external driving force is f(t). The Maple software maybe used to apply Lagrange’s equations to these expressions for kinetic energy, T , potentialenergy V , and the work of non-conservative forces and external forcing, W . Here are theMaple commands:

> with(Physics):> Setup(mathematicalnotation=true)

> v := diff(u(t),t);d

v := -- u(t)dt

> T := (1/2) * M * vˆ2;/d \2

T := 1/2 M |-- u(t)|\dt /

> V := (1/2) * K * u(t)ˆ2;2

V := 1/2 K u(t)

> p := -C * diff(u(t),t) + f(t) ;/d \

p := -C |-- u(t)| + f(t)\dt /

The lines above setup Maple to invoke the desired functional notation, define the ve-locities v as the derivatives of time-dependent displacements u(t), and represent the kineticenergy T, potential energy V, and the external and non-conservative forces p. The subsequentlines evaluate the derivatives and combine the derivatives into Lagrange’s equations to giveus the equations of motion.

CC BY-NC-ND HP Gavin

Page 9: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 9

> dTdv := diff(T, v);/d \

dTdv := M |-- u(t)|\dt /

> ddt_dTdv := diff(dTdv,t);/ 2 \|d |

ddt_dTdv := M |--- u(t)|| 2 |\dt /

> dTdu := diff(T,u(t));dTdu := 0

> dVdu := diff(V,u(t));dVdu := K u(t)

> Q := p*diff(u(t),u(t));/d \

Q := -C |-- u(t)| + f(t)\dt /

> EOM := ddt_dTdv - dTdu + dVdu = Q;

/ 2 \|d | /d \

EOM := M |--- u(t)| + K u(t) = -C |-- u(t)| + f(t)| 2 | \dt /\dt /

> quit

. . . giving us the expected equation of motion (EOM) . . .

Mu(t) + Cu(t) +Ku(t) = f(t)

CC BY-NC-ND HP Gavin

Page 10: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

10 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

9.2 An elastic pendulum

For the elastic pendulum problem considered earlier, the first coordinate is θ(t), and iscalled q(t) in the Maple commands. The second coordinate is u(t) . . . called u(t) in Maple.> with(Physics):> Setup(mathematicalnotation=true)

> v1 := diff(q(t),t);d

v1 := -- q(t)dt

> v2 := diff(u(t),t);d

v2 := -- u(t)dt

> T := (1/2) * M * (( l+u(t))*v1)ˆ2 + (1/2) * M * v2ˆ2;

2 /d \2 /d \2T := 1/2 M (l + u(t)) |-- q(t)| + 1/2 M |-- u(t)|

\dt / \dt /

> V := M * g * ( l - (l+u(t)) * cos(q(t))) + (1/2) * K * u(t)ˆ2;

2V := M g (l - (l + u(t)) cos(q(t))) + 1/2 K u(t)

> EOM1 := diff( diff(T,v1) , t) - diff(T,q(t)) + diff(V,q(t));

/ 2 \/d \ /d \ 2 |d |

EOM1 := 2 M (l + u(t)) |-- q(t)| |-- u(t)| + M (l + u(t)) |--- q(t)|\dt / \dt / | 2 |

\dt /

+ M g (l + u(t)) sin(q(t))

> EOM2 := diff( diff(T,v2) , t) - diff(T,u(t)) + diff(V,u(t));

/ 2 \|d | /d \2

EOM2 := M |--- u(t)| - M (l + u(t)) |-- q(t)| - M g cos(q(t)) + K u(t)| 2 | \dt /\dt /

> quit

The Maple expressions EOM1 and EOM2 are the same equations of motion as the previously-derived equations (35) and (36).

CC BY-NC-ND HP Gavin

Page 11: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 11

10 Matlab simulation of an elastic pendulumTo simulate the dynamic response of a system described by a set of ordinary differential

equations, the system equations may be written in a state variable form, in which the highest-order derivatives of each equation (θ and u in this example) are written in terms of thelower-order derivatives (θ, u, θ, and u in this example). The set of lower-order derivatives iscalled the state vector. In this example, the equations of motion are re-expressed as

θ = −(2uθ + g sin θ)/(l + u) (39)u = (l + u)θ2 − (K/M)u+ g cos θ (40)

In general, the state derivative x = [θ, u, θ, u]T is written as a function of the state, x =[θ, u, θ, u]T, x(t) = f(t, x). The equations of motion are written in this way in the followingMatlab simulation.

1 % elas t i c pendu lum s im2 % simula te the f r e e response o f an e l a s t i c pendulum34 % format and expor t p l o t in . eps5 epsPlots = 0; i f epsPlots , formatPlot (14 ,5); else formatPlot (0); end6 animate = 1;78 % system cons tant s are g l o b a l v a r i a b l e s . . .9

10 global l g K M1112 l = 1.0; % un−s t r e t c h e d l e n g t h o f the pendulum , m13 g = 9.8; % g r a v i t a t i o n a l a c c e l e r a t i o n , m/ s ˆ214 K = 25.6; % e l a s t i c spr ing constant , N/m15 M = 1.0; % pendulum mass , kg1617 fpr intf (’spring -mass frequency = %f Hz\n’, sqrt (K/M )/(2* pi ))18 fpr intf (’pendulum frequency = %f Hz\n’, sqrt (g/l )/(2* pi ))1920 t_final = 36; % simu la t ion duration , s21 delta_t = 0.02; % time s t e p increment , s22 points = f loor ( t_final / delta_t ); % number o f data p o i n t s23 t = [1: points ]* delta_t ; % time data , s2425 % i n i t i a l c o n d i t i o n s2627 theta_o = 0.0; % i n i t i a l r o t a t i o n angle , rad28 u_o = l; % i n i t i a l spr ing s t r e t c h , m29 theta_dot_o = 0.5; % i n i t i a l r o t a t i o n rate , rad/ s30 u_dot_o = 0.0; % i n i t i a l spr ing s t r e t c h rate , m/ s3132 x_o = [ theta_o ; u_o ; theta_dot_o ; u_dot_o ]; % i n i t i a l s t a t e3334 % s o l v e the equa t ions o f motion35 [t,x,dxdt ,TV] = ode4u ( ’elastic_pendulum_sys ’ , t , x_o );3637 theta = x(1 ,:);38 u = x(2 ,:);39 theta_dot = x(3 ,:);40 u_dot = x(4 ,:);4142 T = TV (1 ,:); % k i n e t i c energy43 V = TV (2 ,:); % p o t e n t i a l energy4445 % conver t from ”q” coord ina te s to ” r ” coord ina te s . . .4647 x = (l+u).* sin ( theta ); % eq ’ n (1)48 y = -(l+u).* cos( theta ); % eq ’ n (2)

CC BY-NC-ND HP Gavin

Page 12: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

12 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

1 function [dxdt ,TV] = elastic_pendulum_sys (t,x)2 % [ dxdt ,TV] = e l a s t i c p e n d u l u m s y s ( t , x )3 % system equat ions f o r an e l a s t i c pendulum4 % compute the s t a t e d e r i v a t i v e , dxdt , the k i n e t i c energy , T, and the5 % p o t e n t i a l energy , V, o f an e l a s t i c pendulum .67 % system cons tant s are pre−de f ined g l o b a l v a r i a b l e s . . .89 global l g K M

1011 % d e f i n e the s t a t e ve c t o r1213 theta = x(1); % r o t a t i o n angle , rad14 u = x(2); % spr ing s t r e t c h , m15 theta_dot = x(3); % r o t a t i o n rate , rad/ s16 u_dot = x(4); % spr ing s t r e t c h rate , m/ s1718 % compute the a c c e l e r a t i o n o f t h e t a and u1920 theta_ddot = -(2* u_dot * theta_dot + g* sin ( theta )) / (l+u); % eq ’ n (35)2122 u_ddot = (l+u)* theta_dot ˆ2 - (K/M)*u + g*cos( theta ); % eq ’ n (36)2324 % assemble the s t a t e d e r i v a t i v e2526 dxdt = [ theta_dot ; u_dot ; theta_ddot ; u_ddot ];2728 TV = [ (1/2) * M * ((l+u).* theta_dot ).ˆ2 + (1/2) * M * u_dot .ˆ2 ; % K.E. (25)29 M*g*(l -(l+u).* cos( theta )) + (1/2) * K * u.ˆ2 ]; % P.E. (26)303132 % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− e l a s t i c p e n d u l u m s y s

CC BY-NC-ND HP Gavin

Page 13: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 13

-1

-0.5

0

0.5

1

0 5 10 15 20

θ(t)

and

u(t)

time, s

swing, q1(t) = θ(t), radstretch, q2(t) = u(t), m

-2

-1

0

1

2

3

4

5

6

0 5 10 15 20

ener

gies

, Jou

les

time, s

K.E.P.E.

K.E.+P.E.

-2

-1.5

-1

-0.5

0

-1 -0.5 0 0.5 1

y p

ositio

n,

m

x position, m

(x0, y0)

t = 36.000 s

Figure 1. Free response of an elastic pendulum from an initial rotational velocity, θ(0) of0.5 rad/s for l = 1.0 m, g = 9.8 m/s2, K = 25.6 N/m, and M = 1 kg. Tk = 2π

√M/K =

1.242 s. Tl = 2π√l/g = 2.007 s. Even though Tk/Tl ≈ (

√5 − 1)/2, the least rational

number, the record repeats every 24 seconds. Note that in the absence of internal damping andexternal forcing, the sum of kinetic energy and potential energy is constant. Why is it that theinternal potential energy becomes negative as compared to it’s initial value? What is the initialconfiguration of the system (θ(0), u(0)) in this example? About what values do θ(t) and u(t)oscillate for t > 0? (spyrograph!)

CC BY-NC-ND HP Gavin

Page 14: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

14 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

11 Constraints

Suppose that in a dynamical system described by m generalized dynamic coordinates,

q(t) =[q1(t), q2(t), · · · , qm(t)

]there are specific requirements on the motion that must be satisfied. For example, suppose theelastic pendulum must move along a particular line, g(θ(t), u(t)) = 0, or that the pendulumcan not move past a particular line, g(θ(t), u(t)) ≤ 0. If these constraints to the motion of thesystem can be written pureley in terms of the positions of the coordinates, then the system(including the differential equations and the constraints) is called a holonomic system.

There are a number of intriguing terms connected to constrained dynamical systems.

• A system with constraints that depend only on the position of the coordinates,

g(q(t), t) = 0

is holonomic.

• A system with constraints that depend on the position and velocity of the coordinates,

g(q(t), q(t), t) = 0

(in which g(q(t), q(t), t) can not be integrated into a holonomic form) is non-holonomic.

• A system with constraints that are independent of time,

g(q) = 0 or g(q, q) = 0

is scleronomic.

• A system with constraints that are explicitely dependent on time, as in the constraintslisted under the first two definitions is rheonomic.

• A system with constraints that are linear in the velocities,

g(q(t), q(t)) = f(q(t)) · q(t)

is pfafian.

Any unconstrained system must be forced to adhere to a prescribed constraint. Therequired constraint forces QC are collocated with the generalized coordinates q, and thevirtual work of the constraint forces acting through virtual displacements is zero5

QC · δq = 0.

Geometrically, the constraint forces are normal to the displacement variations.5Lanczos, C., The Variational Principles of Mechanics, 4th ed., Dover 1986

CC BY-NC-ND HP Gavin

Page 15: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 15

11.1 Holonomic systems

Consider a constraint for the elastic pendulum in which the pendulum must move alonga curve g(θ(t), u(t)) = 0. For example, consider the constraint

u(t) = l − lθ2(t) ⇐⇒ g(θ(t), u(t)) = 1− θ2(t)− u(t)/l .

Clearly the elastic pendulum will not follow the path g = 0 all by itself; it needs to be forced,somehow, to follow the prescribed trajectory. In a holonomic system (in which the constraintsare on the coordinate positions) it can be helpful to think of a frictionless guide that enforcesthe dynamics to evolve along a partiular line, g(q) = 0. The guide exerts constraint forcesQC in a direction transverse to the guide, but not along the guide.

For relatively simple systems such as this, incorporating a constraint can be as simpleas solving the constraint equation for one of the variables, for example, u(t) = l− lθ2(t) andusing the constraint to eliminate one of the coordinates. With the substitution of u(t) =l − lθ2(t) into the expressions for kinetic energy and potential energy, Lagranges equationscan be written in terms of the remaining coordinate, θ. This is a perfectly acceptable meansof incorporating holonomic constraints into an analysis. However, in general, a set of cconstraint equations g(q) = 0 can not be re-arranged to express the position of c coordinatesin terms of the remaining (m− c) coordinates. Furthermore, reducing the dimension of thesystem by using the constraint equation to eliminate variables does not give us the forcesrequired to enforce the constraints, and therefore misses an important aspect of the behaviorof the system. So a more general approach is required to derive the equations of motion forconstrained systems.

Recall that an admissible variation, δq must adhere to all constraints. For example, thesolution to the constrained elastic pendulum, perterbued by [δθ, δu], must lie along the curve1− θ2− u/l = 0. In order for the variation δq to be admissible, the perturbed solution mustalso lie on the line of the constraint. In other words, the variation δq must be perpendicularto the gradient of g with respect to q, [

∂g∂q

]δq = 0 . (41)

A constraint evaluated at a perturbed solution q + δq, in general, can be approximated viaa truncated Taylor series

g(q + δq, t) = g(q, t) +[∂g∂q

]δq + h.o.t. .

The constraints at the perturbed solution are satisfied for infinitessimal pertubations as longas equation (41) holds. Because admissible variations δq are normal to [∂g/∂q] and theconstraint force QC is normal to δq, the constraint force must lie within [∂g/∂q],

QC = λT[∂g∂q

].

CC BY-NC-ND HP Gavin

Page 16: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

16 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

q1

δq

g

q

q2

d

d

1 2g(q , q ) = 0

q1

δq

g

q

q2

d

d

.

.

.

g(q , q , q , q ) = 0. .

1 2 1 2

Figure 2. Admissibile variations δq for holonomic (left) and non-holonomic (right) systems. Inholonomic systems δq adheres to the constraint g(q) = 0 since δq is normal to the gradient ofg with respect to q. In holonomic systems δq need only be normal to ∂g/∂q.

The constraint forces QCj may now be added into Lagrange’s equations as the forces

required to adhere the motion to the constraints gi(q) = 0.

d

dt

(∂T

∂qj

)− ∂T

∂qj

+ ∂V

∂qj

−∑

i

λi∂gi

∂qj

−Qj = 0 (42)

in which ∑i

λi∂gi

∂qj

is the generalized force on coordinate qj applied through the system of constraints,

g(q, t) = 0 . (43)

These forces are precisely the actions that enforce the constraints. Equations (42) and (43)uniquely describe the dynamics of the system. In numerical simulations these two systems ofequations are solved simultaneously for the accelerations, q(t), and the Lagrange multipliers,λ(t), from which the constraint forces, QC(t), can be found.

CC BY-NC-ND HP Gavin

Page 17: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 17

Let’s apply this to the elastic pendulum, constrained to move along a path

u(t) = l − lθ2(t) ⇐⇒ g(θ(t), u(t)) = 1− θ2(t)− u(t)/l . (44)

The derivitives of T and V are as they were previously. The new derivitives required tomodel the actions of the constraints are

∂g

∂q1= ∂g

∂θ= −2θ (45)

∂g

∂q2= ∂g

∂u= −1/l (46)

Equation (35) now includes a new term for the constraint force in the θ direction, +λ(2θ),and the new term for the constraint force in the u direction in equation (36) is +λ(1/l). (Thisproblem has one constraint, and therefore one Lagrange multiplier, but two coordinates, andtherefore two generalized constraint forces.) There are no other non-conservative forces Qj

applied to this system. The problem now involves three equations (two equations of motionand the constraint) and three unknowns θ, u (or their derivitives) and λ. In principle, asolution can be found. In solving the equations of motion numerically, as a system of first-order o.d.e’s, we solve for the highest order derivitives in each equation in terms of thelower-order derivitives. In this case the highest order derivitives are θ and u. In the case ofconstrained dynamics, we also need to solve for the Lagrange multiplier(s), λ. The constraintequation(s) give(s) the additional equation(s) to do so. But in this problem the constraintequation is in terms of positions θ and u. However, by differentiating the constraint we canput this in terms of accelerations θ and u. So doing, with some rearrangement,

2lθθ + u = −2lθ2 . (47)

Now we have three equations and three unknowns for θ, u, and λ.

M(l + u)2θ + 2θλ = −Mg(l + u) sin θ −M2(l + u)uθ (48)

Mu+ 1lλ = M(l + u)θ2 −Ku+Mg cos θ (49)

2lθθ + u = −2lθ2 (50)

The constraint force in the θ direction is λ(2θ) and the constraint force in the u direction isλ/l. The three equations may be written in matrix form . . . M(l + u)2 0 2θ

0 M 1/l2θ 1/l 0

θuλ

=

−Mg(l + u) sin θ −M2(l + u)uθM(l + u)θ2 −Ku+Mg cos θ

−2θ2

(51)

Note that the initial condition of the system must also adhere to the constraints,

lθ20 + u0 = l (52)

2lθ0θ0 + u0 = 0 (53)

These equations can be integrated numerically as was shown in the previous Matlab exam-ple, except for the fact that in the presence of constraints, the accelerations and Lagrangemultiplier need to be evaluated as a solution of three equations with three unknowns.

CC BY-NC-ND HP Gavin

Page 18: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

18 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

-1.5

-1

-0.5

0

0.5

1

0 5 10 15 20

θ(t)

and

u(t)

time, s

swing, q1(t) = θ(t), radstretch, q2(t) = u(t), m

0

1

2

3

4

5

0 5 10 15 20

ener

gies

, Jou

les

time, s

K.E.P.E.

K.E.+P.E.

Figure 3. Free response of an undamped elastic pendulum from an initial condition uo = l andθo = 1 constrained to move along the arc u = l − lθ2. The motion is periodic and the totalenergy is conserved exactly.

-2

-1.5

-1

-0.5

0

-1 -0.5 0 0.5 1

y p

ositio

n,

m

x position, m

(x0, y0)

t = 20.000 s

Figure 4. The constrained motion of the pendulum is seen to satisfy the equation u = l − lθ2

for l = 1 m.

-10

-5

0

5

10

15

0 5 10 15 20

θ constraint force, Qθ

u constraint force, Qu

Figure 5. The constraint forces in the θ (blue) and u (green) directions required to enforcethe constraint u(t) = l − lθ2(t).

CC BY-NC-ND HP Gavin

Page 19: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 19

11.2 Non-holonomic systems

A non-holonomic system has internal constraint forces QCj which adhere the responses

to a non-integrable relationship involving the positions and velocities of the coordinates,

g(q, q, t) = 0 . (54)

The constraint forces QCj are normal to the constraint surface g(q, q,t) = 0. As always, any

admissible variations must satisfy the constraints

g(q + δq, q + δq, t) = g(q, q, t) +[∂g∂q

]δq +

[∂g∂q

]δq + h.o.t. = 0

So, for infinitessimal variations, [∂g∂q

,∂g∂q

]·[δqδq

]= 0 .

It may be shown6 that this condition is equivalent to[∂g∂q

]· δq = 0 (55)

which is the constraint on the displacement variations for non-holonomic systems.

As in holonomic constraints, the constraint forces QC in non-holonomic systems do nowork through the displacement variations, δq. Since admissible variations δq are normal to[∂g/∂q], the constraint forces must therefore lie within [∂g/∂q],

QC = λT[∂g(q, q)∂q

].

Including these constraint forces into Lagrange’s equations gives the non-holonomic form ofLagrange’s equations,78

d

dt

(∂T

∂qj

)− ∂T

∂qj

+ ∂V

∂qj

−∑

i

λi∂gi

∂qj

−Qj = 0 , (56)

in which ∑i

λi∂gi

∂qj

is the generalized force on coordinate qj applied through the system of constraints g = 0.Equations (54) and (56) uniquely prescribe the constraint forces (Lagrange multipliers λ)and the dynamics of a system constrained by a function of velocity and displacement.

6P.S. Harvey, Jr., Rolling Isolation Systems: Modeling, Analysis, and Assessment, Ph.D. dissertation,Duke Univ, 2013

7M.R. Flannery, “The enigma of nonholonomic constraints,” Am. J. Physics 73(3) 265-272 (2005)8M.R. Flannery, “d’Alembert-Lagrange analytical dynamics for nonholonomic systems,” J. Mathematical

Physics 52 032705 (2011)

CC BY-NC-ND HP Gavin

Page 20: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

20 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

As an example, suppose the dynamics of the elastic pendulum are controlled by someinternal forces so that the direction of motion arctan(dy/dx) is actively steered to an angleφ that is proportional to the stretch in the spring, φ = −bu/l. The velocity transvese to thesteered angle must be zero, giving the constraint,

u

lθ= tan(θ + bu/l) ⇐⇒ g(θ, u, θ, u) = u cos(θ + bu/l)− lθ sin(θ + bu/l) (57)

The additional derivitives required for the non-holonomic form of Lagranges equations are∂g

∂q1= ∂g

∂θ= −l sin(θ + bu/l) (58)

∂g

∂q2= ∂g

∂u= cos(θ + bu/l) (59)

Equation (35) now includes a new term for the constraint force in the θ direction, −λ(ls),and the new term for the constraint force in the u direction in equation (36) is +λ(c), wheres = sin(θ + bu/l) and c = cos(θ + bu/l). Note that in this case, the constraint forces aredependent upon the position of the pendulum (θ and u), but not on the velocities. Theconstraint equation along with the equations of motion uniquely define the solution θ(t),u(t), and λ(t). Since, for numerical simulation purposes, we are interested in solving for theaccelerations, θ(t) and u(t), we can differentiate the constraint equation to transform it intoa form that is linear in the accelerations,

g = −bu2s/l + uc− lθ2c− lθs− θu(s+ bc) (60)Our three equations are now,

M(l + u)2θ − (ls)λ = −Mg(l + u) sin θ −M2(l + u)uθ (61)Mu+ (c)λ = M(l + u)θ2 −Ku+Mg cos θ (62)

−(ls)θ + (c)u = lθ2c+ θu(s+ bc) + bu2s/l (63)with an initial condition that also satisfies the constraint, u0 = lθ0 tan(θ + bu/l). The threeequations may be written in matrix form . . . M(l + u)2 0 −l sin θ

0 M cos θ−l sin θ cos θ 0

θuλ

=

−Mg(l + u) sin θ −M2(l + u)uθM(l + u)θ2 −Ku+Mg cos θlθ2c+ θu(s+ bc) + bu2s/l

(64)

Note that the upper-left 2 × 2 blocks in the matrices of equations (51) and (64) are thesame as the corresponding matrix M in the unconstrained system (37). The same is truefor the first two elements of the right-hand-side vectors of equations (51) and (64) and theright-hand-side vector Q of the unconstrained system (37). Furthermore, if the differentiatedconstraint equations (47) and (60) are written as

g = A(q(t), q(t)) q(t)− b(q(t), q(t), t)then both equations (51) and (64) may be written[

M AT

A 0

] [qλ

]=[

Qb

]. (65)

This expression can be obtained directly from Gauss’s principle of least constraint, whichprovides an appealing interpretation of constrained dynamical systems.

CC BY-NC-ND HP Gavin

Page 21: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 21

-1

-0.5

0

0.5

1

0 5 10 15 20 25 30 35 40

θ(t)

and

u(t)

time, s

swing, q1(t) = θ(t), radstretch, q2(t) = u(t), m

-2

-1

0

1

2

3

4

5

0 5 10 15 20 25 30 35 40

ener

gies

, Jou

les

time, s

K.E.P.E.

K.E.+P.E.

Figure 6. Free response of an undamped elastic pendulum from an initial condition uo = l/2,θo = 0.2 rad, θo = 1 rad/s, with trajectory constrained by lθ/u = tan(θ + bu/l), with b = 5.The motion is not periodic but total energy is conserved exactly and the constraint is satisfiedat all times.

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

-1.5 -1 -0.5 0 0.5 1 1.5

y p

ositio

n, m

x position, m

(x0, y0)

t = 40.000 s

Figure 7. The constrained motion of the pendulum does not follow a fixed relation between uand θ — the constraint is non-holonomic. (ying & yang)

-250

-200

-150

-100

-50

0

50

100

0 5 10 15 20 25 30 35 40

θ constraint force, Qθ

u constraint force, Qu

Figure 8. The constraint forces in the θ (blue) and u (green) directions required to enforcethe constraint lθ/u = tan(θ + bu/l).

CC BY-NC-ND HP Gavin

Page 22: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

22 CEE 541. Structural Dynamics – Duke University – Fall 2016 – H.P. Gavin

12 Gauss’s Principle of Least ConstraintConsider the equations of motion of the unconstrained system written as equation (38),

M(q, t) q = Q(q, q, t) .The matrix M is assumed to be symmetric and positive definite. Define the accelerations ofthe unconstrained system as

a ≡M−1Qand write the differentiated constraints as

A(q, q, t) q = b(q, q, t).The constrained system requires additional actions QC to enforce the constraint, so theequations of motion of the constrained system are

M(q, t) q = Q(q, q, t) + QC(q, q, t) .Lastly, define a quadratic form of the accelerations,

G = 12 (q − a)T M (q − a)

Gauss’s Principle of Least Constraint910 states that the accelerations of the constrained sys-tem q minimize G subject to the constraints Aq = b. The naturally-constrained accelerationsq are as close as possible to the unconstrained accelerations a in a least-squares sense andat each instant in time while satisfying the constraint Aq = b.

To minimize a quadratic objective subject to a linear constraint the objective can beaugmented via Lagrange multipliers λ,

GA = 12 (q − a)T M (q − a) + λT(A q − b) (66)

= 12 qTMq + qTMa + 1

2aTMa + λTAq − λTb

minimized with respect to q,(∂GA

∂q

)T

= 0 ⇐⇒ Mq = Q−ATλ (67)

and maximized with respect to λ,(∂GA

∂λ

)T

= 0 ⇐⇒ Aq = b (68)

These conditions are met in equation (65), as derived earlier for both holonomic and non-holonomic systems, [

M AT

A 0

] [qλ

]=[

Qb

].

9Hofrath and Gauss, C.F., “Uber ein Neues Allgemeines Grundgesatz der Mechanik,”, J. Reine Ange-wandte Mathematik, 4:232-235. (1829)

10Udwadia, F.E. and Kalaba, R.E., “A New Perspective on Constrained Motion,” Proc. Mathematical andPhysical Sciences, 439(1906):407-410. (1992).

CC BY-NC-ND HP Gavin

Page 23: Generalized Coordinates, Lagrange's Equations, and Constraints 1 ...

Generalized Coordinates and Lagrange’s Equations 23

G(

q" 1

(t),

q" 2

(t)

)

q"1(t)

q"2(t)

G(

q" 1

(t),

q" 2

(t)

)

a1(t)

a2(t) fC(t)=-AT y

Aq"=b

The force of the constraints is now apparent, QC = −ATλ. While equation (65) issufficient for analyzing the behavior and simulating the response of constrained dynamicalsystems, it is also useful in building an understanding of their nature. Solving the first of theequations for q,

q = M−1Q−M−1ATλ

and inserting this expression into the constraint equation,AM−1Q−AM−1ATλ = b

the Lagrange multipliers may be found,λ = −(AM−1AT)−1(b−AM−1Q) ,

and substituting a = M−1Q, the constraint force, QC = −ATλ, can be found as well,QC = −AT(AM−1AT)−1(Aa − b) .

orQC = K(Aa − b) .

The difference (Aa−b) is the amount of the constraint violation associated with the uncon-strained accelerations a. If the unconstrained accelerations satisfy the constraint, then theconstraint force is zero. The matrix K = −AT(AM−1AT)−1 is a kind of natural nonlinearfeedback gain matrix that relates the constraint violation of the unconstrained accelerations(Aa − b) to the constriant force required to bring the constraint to zero, QC .

The constrained minimum of the quadratic objective G gives the correct equations of motion.

CC BY-NC-ND HP Gavin