# Modeling external forces in Lagrangian dynamics

For example, consider a system with a block on a flat, frictionless surface. On one side is a spring connecting the block to a wall. On the other side, a person's hand is pushing the block towards the wall with some constant force.

Normally, the system is formulated in terms of kinetic and potential energy to obtain the Lagrangian. Getting the potential energy of the spring is straightforward, but what about the hand? Or other forces explicitly added to a system? (Another example would be a pendulum with a constant torque at its pivot.)

An external force $F_{\rm ext}(t)$ appears as a source term $qF_{\rm ext}(t)$ in the Lagrangian. For example, if the equation of motion is,

$$\tag{1} m\ddot{q}~=~-\frac{\partial V(q)}{\partial q} + F_{\rm ext}(t),$$

$$\tag{2} L(q,\dot{q},t)~=~\frac{m}{2}\dot{q}^2-V(q)+ qF_{\rm ext}(t).$$

In the case that the force is conservative I would model the force by adding an extra potential term $\psi$ to the Lagrangian such that:

$$\vec{F} = -\nabla\psi$$

If the unforced Lagrangian was $$L_{\text{unforced}} = T - V$$ the forced version is now $$L_{\text{forced}} = T - (V + \psi)$$

As far as I am aware modelling non-conservative forces in the Lagrangian framework is hard so I'd be interested if anyone knows how that is done (or even if it can be in general).

I read the answer somewhere, but now when I was looking to verify it, I found this question instead. So I am doing this from a leaky memory.

What you do is to compute the work done, $W(q)$, by the force as a function of how $q$ (the generalized position) changes. Then the modification to the Euler-Lagrange equations is: $$\frac d{dt}\left(\frac{\partial L}{\partial \dot q}\right) - \frac{\partial L}{\partial q} = \frac{\partial W}{\partial q}$$

For example, consider a double pendulum, where the first pendulum is of length $L_1$, has a mass $m_1$ attached to its end, and makes an angle $\theta_1$ to the vertical, and hanging off this is a second pendulum of length $L_2$, having a mass $m_2$ attached to its end, and making an angle $\theta_2$ to the vertical. Suppose we apply a force $F$ to the mass at the end of the second pendulum, in the horizontal direction. Then $$L = \tfrac12 L_1^2 m_1 \dot \theta_1^2 + \tfrac12 L_2^2 m_2 \dot \theta_2^2 - m_1 g L_1 \cos(\theta_1) - m_2 g \bigl(L_1 \cos(\theta_1) + L_2 \cos(\theta_2)\bigr)$$ and $$W = F \bigl(L_1 \sin(\theta_1) + L_2 \sin(\theta_2)\bigr) .$$ The latter formula is merely force times distance. It only needs to be 'locally true,' that is, correct for small perturbations of $q$.

For a single pendulum with a constant torque $T$ applied at the pivot, we would have $$W = T \theta .$$ So the equation of motion would be $$\ddot \theta + \frac g L \sin \theta = \frac T {L^2 m} .$$