For the past few days, I’ve been trying to teach myself enough Lagrangian mechanics that I can derive systems of ordinary differential equations for the sorts of simple systems that come up in control-theory classes.

I think I’ve kind of got it for mechanical systems, and maybe for electronic ones, but I can’t seem to wrap my head around electromechanical systems. I’m going to dump out a little of my understanding here, to clarify it in my own head, and to get corrections or suggestions from my readers, many of whom are far better at physics than me, having actually taken it in college. My son and I studied simple physics using the textbook *Matter and Interactions* a few years ago, but the book doesn’t get into Lagrangian mechanics, and I don’t think I really understand magnetic fields intuitively well enough to keep the mathematical abstractions straight.

Part of my problem in reading introductions to Lagrangian mechanics (like the Wikipedia one) is that they use almost impenetrable abstract notation and immediately jump to very general cases, leaving me with no intuition about what they are doing.

As I understand it, Lagrangian mechanics starts with the idea of a conserved scalar quantity (like energy), and provides a way of setting up equations of motion by taking partial derivatives with respect to generalized coordinates, which are in turn functions of time.

For mechanical systems the generalized coordinates are generally positions of point masses or angles of joints (velocity and angular velocity are time derivatives of the coordinates). For electronic systems, the generalized coordinates are either charges or voltages and currents, depending whose formulation you read. The charge-based formulation has made a bit more sense to me, as currents are the time-based derivatives of charge. We look at the charge on capacitors and current through inductors to compute energy in the system.

One problem with a lot of the descriptions of Lagrangian mechanics is that they do everything with purely conservative systems, then tack in dissipation as an afterthought, but all real systems that need control have dissipation of energy as a fundamental part of the modeling process. I’ll try to include the dissipation terms in the basic formulation, rather than adding them at the end.

Some notation:

- is the difference between kinetic and potential energy of the system.
~~In a conservative system, it would always be 0, with energy sloshing back and forth between kinetic and potential forms, but never increasing or decreasing.~~Correction based on comments: I screwed up here—it is the sum of kinetic and potential energy (the Hamiltonian) not the difference (the Lagrangian) that is constant in a conservative system. - is the power dissipated by the system.
- is the vector input to the system needed to make the energy balance work out. The units for this vector depend on what the generalized coordinates are. For mechanical systems, Cartesian coordinates will need forces, and angles will need torques. For electronic systems using charges as coordinates, the units are volts.

With this notation, the basic formula is

I may be missing some critical conditions on when this can be applied, but I did manage to work out the equations of motion for an inverted pendulum on a cart from it.

So here is the inverted-pendulum example:

We have two coordinates: the horizontal position of the cart , and the angle of the inverted pendulum (clockwise from upright) . The cart has mass and the pendulum , with a distance from the pivot on the cart to the center of mass for the pendulum . Furthermore, the pendulum has moment of inertia , and there is viscous drag on the cart with a force . The pivot is assumed to be frictionless.

Let’s use to designate the location of the center of mass of the pendulum: .

The potential energy in the system is just due to the height of the pendulum mass: . The kinetic energy is . Combining these gives us

The power dissipated due to friction is .

It would be good to get rid of the extra variable , using just and . The derivative is , and its square is . Substituting that into our previous formula gives us the Lagrangian in terms of just the generalized coordinates and their time derivatives:

Applying the basic formula gives us

We can linearize this around (the inverted pendulum straight up), by setting and , except for the gravitational term, where we use :

These equations of motion can be used to design a controller for the cart and inverted-pendulum system, as long as you don’t let the pendulum get too far from the vertical. I think that the linearized equations are ok, but I may have made some calculus errors in the nonlinear equations I simplified them from.

I’ll stop here, but try to do another (electronic) example in a later blog post.

Good start so far, and certainly right in my wheelhouse so far as well (I’ve never used a Lagrangian formalism in electronics or control theory but I do a ton with mechanics). I don’t think I agree with your statement that L should always be zero. It’s integral over the whole interaction should be minimized, but it doesn’t have to be zero.

Comment by Andy "SuperFly" Rundquist — 2016 October 16 @ 09:17 |

You’re right. I don’t know what I was thinking is unlikely to ever be 0. It is the difference of the derivatives that is usually given in the intros to be 0 (no dissipation and no external forces).

Comment by gasstationwithoutpumps — 2016 October 16 @ 09:59 |

I agree with Andy, not only is the value of L not zero, it’s not going to be constant (for all but the most trivial systems). The value of the Hamiltonian (which is often, but not always, T + V) will be constant in a conservative system, and can be taken to be zero, with the appropriate choice for the zero of potential energy.

I wouldn’t say that dissipation is added to Lagrangian systems “as an afterthought”. I would say that not all dissipation can be shoe-horned into the Lagrangian formulation. With that said, I would be wary of trying to include dissipation as part of L, for fear that I would be limiting my model unnecessarily. But I haven’t done Lagrangians for electronics, so …

Comment by Chris Goedde — 2016 October 16 @ 09:39 |

I agree with Andy and you, there is no reason for to be 0.

I put the dissipation into a separate power term, which seemed to be the most common way to tack it in to the Lagrangian formulation in the intros I tried to understand. Models for control theory usually need to include some handling of dissipation, though often rather crudely approximated (like assuming viscous drag, rather than static friction). In electronics every resistor is a source of dissipation, and neglecting them would really screw up the models!

Comment by gasstationwithoutpumps — 2016 October 16 @ 10:02 |

Drag that is linear in the velocity is used because (1) it is easy to solve and (2) it is identical to R*I damping in AC circuits making for two birds with one stone. If you know one you immediately grasp the other, plus you can solve the mechanical system with an analog electrical system, an approach that was quite common in the olden days before cheap digital computers.

Comment by CCPhysicist — 2016 October 16 @ 19:46 |

I figured that drag linear in velocity was popular because of the ease of modeling. Does it have any resemblance to real forces?

I know that aerodynamic drag on bicycles is usually modeled as proportional to v^2, but that rolling resistance is often modeled as proportional to v.

Hmm, https://en.wikipedia.org/wiki/Drag_(physics) explains that something moving slowly and causing no turbulence will have drag linearly proportional to velocity. That implies to me that neither the v nor the v^2 models are very good in a region of medium speed, where modelers switch from one model to the other. Or is it a sudden transition (onset of turbulence, for example) that switches between which model is appropriate?

Comment by gasstationwithoutpumps — 2016 October 16 @ 20:14 |

[…] post is a continuation of Having trouble learning Lagrangian mechanics, looking at electronic systems rather than mechanical ones. Again, this is not intended as a […]

Pingback by Lagrangian mechanics for linear electronics | Gas station without pumps — 2016 October 16 @ 13:27 |