Lagrangian Equations

Jeff Adams, Wolfram Research Inc.,  October 1992

Introduction

This notebook illustrates one way of using Mathematica to solve some advanced theoretical mechanics problems using Lagrangian Mechanics.  The example problems are taken from Analytical Mechanics, Grant R. Fowles,  Fourth Edition, Saunders College Publishing, 1986.

Function

The function LagrangianEquations[T, V, Q, genCoords] takes four arguments:  the kinetic energy, T, of the system, the potential energy, V, of the system, the non-conservative forces of the system, Q, and a list of the generalized coordinates of the system.
The function returns a list of the lagrangian equations for this system.

Note, it is very important to explicitly declare all dependencies of T,V, and Q on the generalized coordinates, as well as the explicit time dependence of the generalized coordinates.

LagrangianEquations[T_,V_,Q_:0,genCoords_List] :=
	Module[{L=T-V},
	(D[D[L,D[#,t]],t] == Q + D[L,#])& /@ genCoords
	]

Example 1 : Harmonic Oscillator

genCoords = {x[t]};
T = 1/2 m x'[t]^2;
V = 1/2 K x[t]^2;
Q = 0;

LagrangianEquations[T, V, Q, genCoords]

DSolve[%,genCoords,t]

Example 2 :  Harmonic Oscillator with velocity damping

genCoords = {x[t]};
T = 1/2 m x'[t]^2;
V = 1/2 K x[t]^2;
Q = -c x'[t];

LagrangianEquations[T, V, Q, genCoords]

DSolve[%,genCoords,t]

Example 3 : Single Particle in a Central Field

Using polar coordinates

genCoords = {r[t],theta[t]};
T = 1/2 m ( r'[t]^2 + r[t]^2 theta'[t]^2   );
V = v[r[t]];
Q = 0;

LagrangianEquations[T, V, Q, genCoords]

Example 4 :  Atwood's Machine

A mechanical system known as Atwood's machine consists of two weights of mass m1 and m2 , respectively, connected by a light inextensible cord of length l which passes over a pulley.  The system has one degree of freedom.  Let x represent the configuration of the system, where x is the vertical distance from the pulley to m1.  I is the moment of inertia of the pulley with radius a.

genCoords = {x[t]};
T = 1/2 m1 x'[t]^2 + 1/2 m2 x'[t]^2 + 1/2 I x'[t]^2/ a^2;
V = -m1 q x[t] - m2 q (l - x[t]);
Q = 0;

LagrangianEquations[T, V, Q, genCoords]

Solve[%, x''[t]]

Example 5 :  Double Atwood  Machine

Replace one of the weights in the atwood machine by another pulley supporting two weights connected by another cord.  The system now has two degrees of freedom.  We shall specify the coordinates x1 and x2.  For simplicity we shall neglect the masses of the pulleys in this case.

genCoords = {x1[t],x2[t]};
T = 1/2 m1 x1'[t]^2 + 1/2 m2 (-x1'[t] + x2'[t])^2 +
	 1/2 m3 ( -x1'[t] - x2'[t])^2;
V = -m1 q x1[t] - m2 q (l1 - x1[t] + x2[t]) -
	m3 g (l1 - x1[t] + l2 - x2[t]);
Q = 0;

LagrangianEquations[T, V, Q, genCoords]

Simplify[ Solve[%, {x1''[t],x2''[t]}] ]

Example 6 :  Particle Sliding on a Movable Inclined Plane

Consider a particle sliding on a smooth inclined plane which itself, is free to slide on a smooth horizontal surface. There are two degrees of freedom x1 and x2, the horizontal displacement of the plane from some reference point and the displacement of the particle from some reference point on the plane.  Using the law of cosines for the velocity of the particle, we have:

genCoords = {x1[t],x2[t]};
T = 1/2 m (x1'[t]^2 + x2'[t]^2+2 x1'[t] x2'[t] Cos[theta]) +
		1/2 M x1'[t]^2;
V = - m q x2[t] Sin[theta] + cons;
Q = 0;

LagrangianEquations[T, V, Q, genCoords]

Simplify[ Solve[%, {x1''[t],x2''[t]}] ]

Example 7 :  Spherical pendulum, or bar of soap in a bowl

genCoords = {theta[t],phi[t]};
T = 1/2 m l^2 (theta'[t]^2 + Sin[theta[t]]^2 phi'[t]^2);
V = m g l (1 - Cos[theta[t]]);
Q = 0;

LagrangianEquations[T, V, Q, genCoords]

Given that phi is an ignorable coordinate then  m l^2 Sin[theta[t]]^2  phi'[t] = constant

%  /.  phi'[t] -> h1/ (m l^2 Sin[theta[t]]^2 )

Solve[%,theta''[t]]

thetaEqu = Simplify[ % /. {h1 -> h l^2 m}]

In one special case, if phi = constant then phi' is zero and so h=0 and we have the simple pendulum case.