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.)
 A: 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), $$
then the Lagrangian reads
$$\tag{2} L(q,\dot{q},t)~=~\frac{m}{2}\dot{q}^2-V(q)+ qF_{\rm ext}(t).$$
A: 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).
A: 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} .$$
A: I would say that when external non-conservative forces are present in a system, the model is designed by means of d'Alabert's principle, i.e. the principle of virtual work, which generalizes Euler-Lagrange.
D'Alamber's principle (principle of virtual work) states that the variation
$$\int_{t_0}^{t_1}\, \Big(\,  \delta L\big(q, \, \dot{q}, \, t\big) \, - \,Q(q,\, \dot{q}, t) \cdot \delta q \,  \, \Big) dt \, = \, 0$$ for any variation $\delta q = \delta q(t)$ of the trajectory of the system $q = q(t)$ that connects two fixed events $(q_0, t_0)$ and $(q_1, t_1)$. Just like in the case of Euler-Lagrange, a trajectory  $q = q(t)$ is a solution, exactly when
$$\int_{t_0}^{t_1} \left( \, \Big[\,\,  \frac{d}{dt}\Big(\, \frac{\partial L}{\partial \dot{q}}\big(q, \, \dot{q}, \, t\big) \, \Big) \, -  \, \frac{\partial L}{\partial \dot{q}}\big(q, \, \dot{q}, \, t\big)\,\Big] \cdot \delta q \, - \, Q(q,\, \dot{q}, t) \cdot \delta q \,  \, \right) dt \, = \, $$
$$\int_{t_0}^{t_1} \left( \, \Big[\,\,  \frac{d}{dt}\Big(\, \frac{\partial L}{\partial \dot{q}}\big(q, \, \dot{q}, \, t\big) \, \Big) \, -  \, \frac{\partial L}{\partial \dot{q}}\big(q, \, \dot{q}, \, t\big) \, - \, Q(q,\, \dot{q}, t) \, \Big] \cdot \delta q \,  \, \right) dt \, = \, 0$$ which yields the equations
$$\frac{d}{dt}\Big(\, \frac{\partial L}{\partial \dot{q}}\big(q, \, \dot{q}, \, t\big) \, \Big) \, -  \, \frac{\partial L}{\partial \dot{q}}\big(q, \, \dot{q}, \, t\big) \, = \, Q(q,\, \dot{q}, t)$$
