+
Lagrangian dynamics
Developed by Andy Rundquist  Published October 3, 2016
This set of exercises guides the student in exploring how to use a computer algebra system to determine the equations of motion for a dynamical system using a Lagrangian formalism, and then how to use numerical solving to analyze the resulting motion.
Subject Area  Mechanics 

Levels  Beyond the First Year and Advanced 
Available Implementation  Mathematica 
Learning Objectives 
Students will
* Be able to identify the relevant parameters of a system and understand how to represent them with variables,
* Be able to code in the appropriate Lagrangian differential equations that represent the equations of motion for the system,
* Be able to produce pseudocode for how the numeric integration will work,
* Be able to use modern differential equation solvers to produce the interpolated dynamics of the system,
* Be able to plot the motion of the system,
* Be able to use Lagrangian multipliers and constraints to identify the timedependent constraint forces.

Time to Complete  60 min 
For most of the exercises below, the context can be almost any dynamical system, but for concreteness we will focus on a problem that involves a double pendulum hung from a support that moves with constant speed around a vertical circle.
![sample problem diagram](images/lagrangian/diagram.png)
1. Identify the variables and determine an expression for the kinetic and potential energy.
For a given dynamical system, identify the appropriate variables and determine an expression for the kinetic and potential energies (and hence the Lagrangian, which is KEPE). For later plotting purposes (and animation creations) it's often easiest to come up with expressions for the Cartesian variables of all moving parts. This also makes the determination of the energies easier, especially for simple one dimensional gravity.
2. Determine the appropriate EulerLagrange equations
Using a Computer Algebra System determine the equations of motion for the relevant variables (the two angles in the problem above) by calculating the EulerLagrange equation:
$$\frac{\partial \mathcal{L}}{\partial q_i(t)}\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial q_i'(t)}=0$$
3. Produce pseudocode for the integration of the equations of motion
Each equation of motion is a secondorder differential equation. Break each into two first order differential equations by noting that q'(t) can be written as v'(t). Usually q'(t) = v(t) is one of the two first order equations. For each, consider an Euler method style time step procedure to determine the next time step's value for all the q's and all the v's. Finally, identify the proper initial conditions for all the q's and v's.
4. Solve the equations of motion and plot the results and animation
Code the equations of motion into a differential equation solver, along with appropriate initial conditions. Plot the dynamical variables as functions of time and produce an animation of the motion.
5. Determine the equations of motion for a system with a constraint using Lagrange multipliers
To find the value(s) of the constraint force(s), use a Lagrange multiplier. For the tension in the first leg of the double pendulum above, you would have a constraint equations noting that the distance between the support and the first mass is a constant. You would also change all the Euler Lagrange equations:
$$\frac{\partial \mathcal{L}}{\partial q_i(t)}\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial q_i'(t)}+\sum \lambda_j(t) \frac{\partial C_j}{\partial q_i(t)}=0$$
Where "C" is an expression for the length of the first leg. The differential equation solver now needs to be told about the constraint (or, more usefully, that the second derivative of C is zero) along with the modified EulerLagrange equations. Note that because the Lagrange multiplier never has any derivatives taken on it, you don't have to provide initial conditions for it. However, it will (likely) vary in time and so it can be plotted to examine aspects like the maximum force and where or if the force ever changes sign.
6. Add nonconservative forces (friction) to the model
Any nonconservative forces (like viscous friction) can be added to the right hand side of the Euler Lagrange equation. Due to the sign convention weâ€™re using here, they should be added with an extra negative sign. For example, if you wanted to add viscous friction to the first mass in our problem above, the right hand side would be proportional to $\theta'(t)$.
Download Options
Share a Variation
Did you have to edit this material to fit your needs? Share your changes by
Creating a Variation
Credits and Licensing
Andy Rundquist, "Lagrangian dynamics," Published in the PICUP Collection, October 2016.
The instructor materials are ©2016 Andy Rundquist.
The exercises are released under a Creative Commons AttributionNonCommercialShareAlike 4.0 license