Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
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 positionof the mass at any point in time may be expressed in Cartesian coordinates (x(t), y(t)) orin 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 pivotpoint,
θ
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 withall 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)
2 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
δy = ∂y
∂θδθ + ∂y
∂uδu = (l + u(t)) sin θ(t)δθ − cos θ(t)δu (7)
2 Principle of Virtual Displacements
Virtual displacements δri are any displacements consistent with the constraints of thesystem. 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 miri(t), potential energy V (r), and n external forces pi collocated with coordinates ri,the principle of virtual dispalcements says,
n∑i=1
(miri + ∂V
∂ri
)δri =
n∑i=1
(pi(t)) δri (8)
3 Derivation of d’Alembert’s principle from Minimum Total Potential Energy
The total potential energy, Π, is defined as the internal potential energy, V , minus thepotential 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 (??).
Π(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 “vari-ational” 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) = −miri(t) + pi(t) , (11)where pi is an external force collocated with the displacement coordinate ri. Substitutingequation (??) into equation (??), and rearranging slightly, results in the d’Alembert equa-tions, the same as equation (??) found from the principle of virtual displacements,
n∑i=1
(miri(t) + ∂V
∂ri
− pi(t))δri = 0 . (12)
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 .
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 3
In equations (??) and (??) the virtual displacements (i.e., the variations) δri must be ar-bitrary and independent of one another; these equations must hold for each coordinate ri
individually.miri(t) + ∂V
∂ri
− pi(t) = 0 . (13)
4 Derivation of Lagrange’s equations from d’Alembert’s principle
For many problems equation (??) 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 miri δ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 + r23), and
∂T
∂ri
δri = miri δri . (15)
Applying the product and chain rules of calculus to equation (??),
d
dt
(∂T
∂ri
δri
)= miri δri +miri
d
dtδri (16)
d
dt
∂T∂ri
m∑j=1
∂ri
∂qj
δqj
= miri δri + ∂T
∂ri
δri (17)
miri δri = d
dt
∂T∂ri
m∑j=1
∂ri
∂qj
δqj
− ∂T
∂ri
m∑j=1
∂ri
∂qj
δqj . (18)
Equation (??) is a step to getting the work of inertial forces (∑i miri δri) in terms of a setof generalized coordinates qj. Next, changing the derivatives of the potential energy from ri
to qj,∂V
∂ri
δri =m∑
j=1
∂V
∂qj
∂qj
∂ri
∂ri
∂qj
δqj . (19)
Finally, expressing the work of non-conservative forces pi in terms of the new coordinates qj,n∑
i=1pi(t) δri =
n∑i=1
pi(t)m∑
j=1
∂ri
∂qj
δqj =m∑
j=1
n∑i=1
pi(t)∂ri
∂qj
δqj =m∑
j=1Qj(t) δqj , (20)
cbnd H.P. Gavin September 1, 2020
4 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
where Qj(t) are generalized forces, collocated with the generalized coordinates, qj(t). Substi-tuting equations (??), (??) and (??) into d’Alembert’s equation (??), rearranging the orderof the summations, factoring out the common δqj, canceling the ∂ri and ∂ri terms, andeliminating the sum over i, leaves the equation in terms 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.
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 5
6 Derivation of Hamilton’s principle from d’Alembert’s principle
The variation of the potentential energy V (r) may be expressed in terms of variationsof the coordinates ri
δV =n∑
i=1
∂V
∂ri
δri =n∑
i=1fi δri . (24)
where fi are potential forces collocated with coordiantes ri. In Cartesian coordinates, thevariation of the kinetic energy T (r)
T =n∑
i=1
12mir
2i (25)
may be expressed in terms of variations of the coordinate velocities, ri
δT =n∑
i=1
∂T
∂ri
δri =n∑
i=1mri δri . (26)
For a system of n particle masses mi acted on by n internal forces fi of the potential V ,d’Alembert’s principle (?? or ??), is
n∑i=1
miri δri +n∑
i=1fi δri = 0 (27)
Integrating d’Alembert’s equation over a finite time period,∫ t2
t1
n∑i=1
miri δri dt+∫ t2
t1
n∑i=1
fi δri dt = 0
n∑i=1
∫ t2
t1mi
d
dtri δri dt+
∫ t2
t1δV dt = 0
n∑i=1
[miri δri|t2
t1−∫ t2
t1miri
d
dtδri dt
]+∫ t2
t1δV dt = 0
−∫ t2
t1
n∑i=1
miri δri dt+∫ t2
t1δV dt = 0
−∫ t2
t1δT dt+
∫ t2
t1δV dt = 0
δ∫ t2
t1(T − V ) dt = 0 (28)
In this derivation we consider a variation of the coordinate motions δr(t) from t1 to t2. Thatis, δr(t1) = 0 and δr(t2) = 0, which eliminates the first term in the third line. The fourthline involves a transposition of the variation and the derivitive (d(δr)/dt = δr). The last lineis a statement of Hamilton’s principle, which is presented formally in the next section. Notethat kinetic energy and potential energy are scalar valued quantities, invariant to changes incoordiante systems. So, while Hamilton’s principle is derived here in the context of Cartesiancoordinates, it applies to generalized coordinates, as well.
cbnd H.P. Gavin September 1, 2020
6 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
7 Derivation of Lagrange’s equations from Hamilton’s principle
Define a Lagrangian of kinetic and potential energies
L(q, q, t) ≡ T (q, q, t)− V (q, t) (29)
and define an action potential functional
S[q(t)] =∫ t2
t1L(q, q, t) dt (30)
with end points q1 = q(t1) and q2 = q(t2). Consider the true path of q(t) from t1 to t2 anda variation of the path, δ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, (31)
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
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 7
8 A Little History
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 = 0cbnd H.P. Gavin September 1, 2020
8 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
9 Example: an elastic pendulumFor an elastic pendulum (a mass swinging on the end of a spring), it is much easier to
express 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 (32)
V (θ, u) = Mg(l − (l + u) cos θ) + 12Ku
2 (33)
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θ) (34)
∂T
∂q1= ∂T
∂θ= 0 (35)
∂V
∂q1= ∂V
∂θ= Mg(l + u) sin θ (36)
d
dt
∂T
∂q2= d
dt
∂T
∂u= d
dtMu = Mu (37)
∂T
∂q2= ∂T
∂u= M(l + u)θ2 (38)
∂V
∂q2= ∂V
∂u= Ku−Mg cos θ (39)
Substituting these derivatives into Lagrange’s equations for q1 gives
M(2(l + u)uθ + (l + u)2θ) +Mg(l + u) sin θ = 0 . (40)
Substituting these derivatives into Lagrange’s equations for q2 gives
Mu−M(l + u)θ2 +Ku−Mg cos θ = 0 . (41)
These last two equations represent a pair of coupled nonlinear ordinary differential equa-tions describing the unconstrained motion of an elastic pendulum. Equation (??) representsmoments (N.m) collocated with θ. Equation (??) represents forces (N) collocated with u.They may be written in matrix form as[
M(l + u)2 00 M
] [θu
]=[−Mg(l + u) sin θ − 2M(l + u)uθM(l + u)θ2 −Ku+Mg cos θ
](42)
orM (q(t), t) q(t) = Q(q(t), q(t), t) (43)
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.
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 9
10 Maple and Mathematica software to compute derivatives for Lagrange’sequations
10.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,in which the damping force is cu and the external driving force is f(t).
10.1.1 Using Maple
The Maple software may be used to apply Lagrange’s equations to these expressions forkinetic energy, T , potential energy V , and the work of non-conservative forces and externalforcing, W . Here are the Maple 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 kinetic
cbnd H.P. Gavin September 1, 2020
10 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
energy 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.
> 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)
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 11
10.1.2 Using Mathematica
The same problem using Mathematica software is solved as follows:
v[t] = D[u[t], t]u ’[t]
T[t] = 1 / 2 * M * v[t]ˆ2(1/2) M u ’ [t] 2
V[t] = 1 / 2 * K * u[t]ˆ2(1/2) K u[t] 2
Q[t] = - C D[u[t], t] + f[t]f[t] - C u ’ [t]
dTdv[t] = D[T[t], v[t]]M u ’ [t]
ddTdvdt[t] = D[dTdv[t], t]M u" [t]
dVdu[t] = D[V[t], u[t]]K u[t]
dTdu[t] = D[U[t], u[t]]0
EOM = ddTdvdt[t] - dTdu[t] + dVdu[t] == Q[t]K u[t] + M u"[t] == f[t] - C u’[t]
cbnd H.P. Gavin September 1, 2020
12 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
10.2 An elastic pendulum
For the elastic pendulum problem considered earlier, the first coordinate is θ(t), and iscalled q(t) in the Maple commands and q[t] in the Mathematica commands.. The secondcoordinate is u(t) . . . called u(t) in Maple and u[t] in Mathematica.
10.2.1 Using 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)
> EOMq := diff( diff(T,v1) , t) - diff(T,q(t)) + diff(V,q(t));
/ 2 \/d \ /d \ 2 |d |
EOMq := 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))
> EOMu := diff( diff(T,v2) , t) - diff(T,u(t)) + diff(V,u(t));
/ 2 \|d | /d \2
EOMu := M |--- u(t)| - M (l + u(t)) |-- q(t)| - M g cos(q(t)) + K u(t)| 2 | \dt /\dt /
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 13
10.2.2 Using Mathematica
KE = 1/2 * M * ((l + u[t]) * D[q[t], t])ˆ2 + 1/2 * M * D[u[t], t]ˆ2(1/2) M (l + u[t])ˆ2 q’[t]ˆ2 + (1/2) M u’[t]ˆ2
PE = M * g * (l - (l + u[t]) * Cos[q[t]]) + 1/2 * K * u[t]ˆ2(1/2) K u[t]ˆ2 + g M (l - Cos[q[t]] (l + u[t]))
Collect[EOMq = D[D[KE, D[q[t], t]], t] + D[PE - KE, q[t]], {q’’[t], q’[t], q[t]}]g M Sin[q[t]] (l + u[t]) + 2 M (l + u[t]) q’[t] u’[t] + M (l + u[t])ˆ2 q"[t]
Collect[EOMu = D[D[KE, D[u[t], t]], t] + D[PE - KE, u[t]], {u ’’[t], u ’[t], u[t]}]-g M Cos[q[t]] - l M q’[t]ˆ2 + u[t] (K - M q’[t]ˆ2) + M u"[t]
The Maple and Mathematica expressions EOMq and EOMu are the same equations ofmotion as the previously-derived equations (??) and (??).
cbnd H.P. Gavin September 1, 2020
14 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
11 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) (44)u = (l + u)θ2 − (K/M)u+ g cos θ (45)
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 animate = 1; % 1: animate the response5 MakeMovie = 1; % 1: make a movie , 0 : don ’ t .678 % 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)
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 15
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
cbnd H.P. Gavin September 1, 2020
16 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
-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 dampingand external forcing, the sum of kinetic energy and potential energy is constant. Why is itthat the internal potential energy becomes negative as compared to it’s initial value? Whatis the initial configuration of the system (θ(0), u(0)) in this example? About what valuesdo θ(t) and u(t) oscillate for t > 0? (spyrograph!) An animation of this motion is here:http://www.duke.edu/∼hpgavin/cee541/elastic pendulum sim.mp4
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 17
12 ConstraintsSuppose that in a dynamical system described by m generalized dynamic coordinates,
q(t) =[q1(t), q2(t), · · · , qm(t)
]the coordinate trajectories must satisfy additional (constraining) relationships g(q) = 0. Forexample, suppose the elastic pendulum must move along a particular line, g(θ(t), u(t)) =0, or that the pendulum can not move past a particular line, g(θ(t), u(t)) ≤ 0. If theseconstraints to the motion of the system can be written pureley in terms of the positions ofthe coordinates, then the system (including the differential equations and the constraints) iscalled 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 nonholonomic.
• 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
cbnd H.P. Gavin September 1, 2020
18 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
12.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 beforced, somehow, to follow the prescribed trajectory. In a holonomic system (in which theconstraints are on the coordinate positions) it can be helpful to think of a frictionless guidethat enforces the dynamics to evolve along a partiular line, g(q) = 0. The guide exertsconstraint forces QC 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 simple assolving the constraint equation for one of the coordinates, for example, u(t) = l− lθ2(t) andsubstituting that expression into the Lagrangian or the unconstrained equations of motion.With the substitution of u(t) = l−lθ2(t) into the expressions for kinetic energy and potentialenergy, Lagranges equations can be written in terms of the remaining coordinate, θ. This is aperfectly acceptable means of incorporating holonomic constraints into an analysis. However,in general, a set of c constraint equations g(q) = 0 need not be re-arranged to express theposition of c coordinates in terms of the remaining (m − c) coordinates. Furthermore,reducing the dimension of the system by using the constraint equation to eliminate variablesdoes not give us the forces required to enforce the constraints, and therefore misses animportant aspect of the behavior of the system. So a more general approach can be followedin order to derive the equations of motion for constrained systems.
Recall that an admissible variation, δq must adhere to all constraints. For example,the solution to the constrained elastic pendulum, perterbued by [δθ, δu], must lie along thecurve 1− θ2−u/l = 0. In order for the variation δq to be admissible, the perturbed solutionmust also lie on the line of the constraint. A constraint evaluated at a perturbed solutionq + δq, in general, can be approximated via a 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 the variation δq is orthogonal to the gradient of g with respect to q,[
∂g
∂q
]δq = 0 . (46)
Because admissible variations δq are normal to [∂g/∂q] and the constraint forceQC is normalto δq, the constraint force must lie within the subspace spanned by [∂g/∂q],
QC = λT[∂g
∂q
].
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 19
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 nonholonomic (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 nonholonomic 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 (47)
in which ∑i
λi∂gi
∂qj
is the generalized force on coordinate qj applied through the system of constraints,
g(q, t) = 0 . (48)
These forces are precisely the actions that enforce the constraints. Equations (??) and (??)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.
A system with m coordinates and c holonomic constraints can be reduced to a systemof m − c equations of motion by substituting constraint equations into the equations ofmotion and eliminating coordinates. Alternatively, the Lagrange multipliers can be treatedas dynamic variables, and the constraint equations can be enforced in the acceleration form,by differentiating them twice with respect to time. In either case, the initial conditions mustbe admissible, and numerical integration errors that would lead to dynamic responses thatviolate g(q, t) = 0 must be numerically corrected.
cbnd H.P. Gavin September 1, 2020
20 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
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 . (49)
The derivitives of T and V are as they were. The new derivitives required to model theactions of the constraints are
∂g
∂q1= ∂g
∂θ= −2θ (50)
∂g
∂q2= ∂g
∂u= −1/l (51)
Note that these derivites are related to, but are not the same as, the gradient of g(q).Equation (??) now includes a new term for the constraint moment in the θ direction, +λ(2θ),and the new term for the constraint force in the u direction in equation (??) is +λ(1/l). (Thisproblem has one constraint, and therefore one Lagrange multiplier, but two coordinates, andtherefore two generalized constraint forces.) The Lagrange multiplier in this problem hasunits of moment (N.m). There are no other non-conservative forces Qj applied to this system.The problem now involves three equations (two equations of motion and the constraint) andthree unknowns θ, u (or their derivitives) and λ. In principle, a solution can be found. Insolving the equations of motion numerically, as a system of first-order o.d.e’s, we solve for thehighest order derivitives in each equation in terms of the lower-order derivitives. In this casethe highest order derivitives are θ and u. In the case of constrained dynamics, we also needto solve for the Lagrange multiplier(s), λ. The constraint equation(s) give(s) the additionalequation(s) to do so. But in this problem the constraint equation is in terms of positions θand u. However, by differentiating the constraint we can put this in terms of accelerationsθ and u. So doing, with some rearrangement,
2lθθ + u = −2lθ2 . (52)
Now we have three equations and three unknowns for θ, u, and λ.
M(l + u)2θ + 2θλ = −Mg(l + u) sin θ − 2M(l + u)uθ (53)
Mu+ 1lλ = M(l + u)θ2 −Ku+Mg cos θ (54)
2lθθ + u = −2lθ2 (55)
The constraint moment in the θ direction is λ(2θ) and the constraint force in the u directionis λ/l. The constraint forces acting along g(q) = 0 are λ/l in the u direction and 2θλ/(l+u)perpendicular to the u direction. 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 θ − 2M(l + u)uθM(l + u)θ2 −Ku+Mg cos θ
−2θ2
(56)
Note that the initial condition of the system must also adhere to the constraints,
lθ20 + u0 = l (57)
2lθ0θ0 + u0 = 0 (58)
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 21
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.
cbnd H.P. Gavin September 1, 2020
22 CEE 541. Structural Dynamics – Duke University – Fall 2020 – 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. An animation of this motion and the dynamic constraint forces is here: http://www.duke.edu/∼hpgavin/cee541/elastic pendulum H sim.mp4
-10
-5
0
5
10
15
0 5 10 15 20
θ constraint force, Qθ
u constraint force, Qu
Figure 5. The constraint moment in the θ direction (blue) and force in the u direction (green)required to enforce the constraint u(t) = l − lθ2(t).
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 23
12.2 Nonholonomic systems
A nonholonomic 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 . (59)
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 (60)
which is the constraint on the displacement variations for nonholonomic systems.
Since admissible variations δq are normal to [∂g/∂q], the constraint forces must there-fore lie within [∂g/∂q],
QC = λT[∂g(q, q)∂q
].
Including these constraint forces into Lagrange’s equations gives the nonholonomic form ofLagrange’s equations,7 8
d
dt
(∂T
∂qj
)− ∂T
∂qj
+ ∂V
∂qj
−∑
i
λi∂gi
∂qj
−Qj = 0 , (61)
in which ∑i
λi∂gi
∂qj
is the generalized force on coordinate qj applied through the system of constraints g = 0.Equations (??) and (??) 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)
cbnd H.P. Gavin September 1, 2020
24 CEE 541. Structural Dynamics – Duke University – Fall 2020 – 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) (62)
The additional derivitives required for the nonholonomic form of Lagranges equations are∂g
∂q1= ∂g
∂θ= −l sin(θ + bu/l) (63)
∂g
∂q2= ∂g
∂u= cos(θ + bu/l) (64)
Equation (??) now includes a new term for the constraint moment in the θ direction, −λ(ls),and the new term for the constraint force in the u direction in equation (??) 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) (65)Our three equations are now,
M(l + u)2θ − (ls)λ = −Mg(l + u) sin θ − 2M(l + u)uθ (66)Mu+ (c)λ = M(l + u)θ2 −Ku+Mg cos θ (67)
−(ls)θ + (c)u = lθ2c+ θu(s+ bc) + bu2s/l (68)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 −ls
0 M c−ls c 0
θuλ
=
−Mg(l + u) sin θ − 2M(l + u)uθM(l + u)θ2 −Ku+Mg cos θlθ2c+ θu(s+ bc) + bu2s/l
(69)
Note that the upper-left 2 × 2 blocks in the matrices of equations (??) and (??) are thesame as the corresponding matrix M in the unconstrained system (??). The same is truefor the first two elements of the right-hand-side vectors of equations (??) and (??) and theright-hand-side vectorQ of the unconstrained system (??). Furthermore, if the differentiatedconstraint equations (??) and (??) are written as
g = A(q(t), q(t)) q(t)− b(q(t), q(t), t)then both equations (??) and (??) may be written[
M AT
A 0
] [qλ
]=[Qb
]. (70)
This expression can be obtained directly from Gauss’s principle of least constraint, whichprovides an appealing interpretation of constrained dynamical systems.
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 25
-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), rad
stretch, q2(t) = u(t), m
-2-1012345
0 5 10 15 20 25 30 35 40
ener
gies,
Joules
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
-2 -1 0 1 2
y p
osi
tion, 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 u andθ — the constraint is nonholonomic. An animation of this motion and the dynamic constraintforces is here: http://www.duke.edu/∼hpgavin/cee541/elastic pendulum NH sim.mp4 (ying &yang)
-60
-40
-20
0
20
40
0 5 10 15 20 25 30 35 40
θ constraint moment, Qθ
u constraint force, Qu
Figure 8. The constraint moment in the θ direction (blue) and the force u direction (green)directions required to enforce the constraint lθ/u = tan(θ + bu/l).
cbnd H.P. Gavin September 1, 2020
26 CEE 541. Structural Dynamics – Duke University – Fall 2020 – H.P. Gavin
13 Gauss’s Principle of Least ConstraintConsider the equations of motion of the unconstrained system written as equation (??),
M(q, t) a = Q(q, q, t) .The matrix M is assumed to be symmetric and positive definite. Define the accelerationsof the unconstrained system as
a ≡M−1Q
and write the differentiated constraints in terms of the constrained accelerations q asA(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 constraintsAq = 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) (71)
= 12 q
TMq + qTMa+ 12a
TMa+ λTAq − λTb
minimized with respect to q,(∂GA
∂q
)T
= 0 ⇐⇒ M q = Q−ATλ (72)
and maximized with respect to λ,(∂GA
∂λ
)T
= 0 ⇐⇒ Aq = b (73)
These conditions are met in equation (??), 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).
cbnd H.P. Gavin September 1, 2020
Generalized Coordinates and Lagrange’s Equations 27
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 (??) 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 ofthe equations 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.
cbnd H.P. Gavin September 1, 2020