Today we are going to go over a very useful tool used by engineers to explicitly write out the dynamics as some simple systems. And then go over a popular method of controlling those systems. Just a word of warning, the math in this lecture is a little more involved than many of the previous lectures. But our intention in doing this is to give you practical engineering tools that you can use to apply to real problems. You likely learned about Newton's laws in your introductory physics course. It tell us that mechanical systems of a second order differential equations. Meaning differential equations, where there are no more than two derivatives in it of any variable. Newton's laws let us model the accelerations of robots. It's functions of their speed, velocity, and external forces. In a kinematic section of this course, you'll learn how to generate the equations and motion for a system using free-body diagrams. Free-body diagrams work well in simple systems but often times robotic models use complicated geometries and coordinate systems. It can make free-body diagrams cumbersome. In these cases, writing out the components of the internal forces can be tedious. Especially when using rotate coordinate systems which is pretty common when modeling robot joints. Often times, writing out the energy of such systems is much simpler than writing out all the forces. It turns out that there is another way of generating the equations of motions for a system from the mechanical energy alone so you don't need to write out all the forces. This formulation is known as Lagrangian mechanics. And is another equivalent way of expressing Newton's laws. For systems that aren't acted upon by outside forces, Lagrangian mechanics says that the equations of motion are given by taking the kinetic energy subtracting potential energy and then applying a special expression called the Euler-Lagrange operator and setting the result to zero. One big advantage of Lagrangian mechanics is that since this process is so simple, it is easy to automate in software, once you can write down the system's energy. Let's go over this in more detail before we do a simple example. The mechanical energy of a system is the sum of its kinetic energy, the energy from its motion and potential energy, for example the energy due to gravity or springs. Even in complicated systems, the kinetic and potential energies are often much easier to write out than the forces. The difference between the kinetic and the potential energy has a name and it's called the Lagrangian. By applying the Euler-Lagrange operator to the Lagrangian and setting the result to zero you get the equation summation. The Euler-Lagrange operator simply takes the partial derivative of velocities, differentiates that with respect to time and subtracts away the partial derivative of positions. The form of the Euler-Lagrange operator, and the reason all of this works, is a consequence of the principle in physics called the principle of least action. We don't have time to go into the details of it today, but feel free to look it up online if you're interested. Finally, all of this accounts for internal forces, but if external forces are acting on the system all you need to do is replace these forces with a zero at the end. As a quick example of how to use Lagrangian mechanics let's derive the equations in motion for a simple pendulum. A simple pendulum consists of a mass m attached to a rod of length l that is free to rotate around sub-stationary pivot point. Gravity pulls mass downwards. Let's say that when a rod is vertically downwards it has an angle of zero radiance. So the state of the system is given by the rod angle and a rod angular velocity. The first step is to rate out the kinetic and potential energy for the system. The kinetic energy is given by one half a moment of inertia times the angular velocity squared. Which simplifies to one-half the mass times the rod length squared times the angle of the velocity squared. The potential energy is simply the energy due to gravity which is equal to the negative of the mass times the rod length times the acceleration due to gravity times the cosine of the rod angle. Lagrangian is then the difference between the kinetic and the potential energy. Let's apply the Euler-Lagrange operator to the system turn by turn. The partial derivative of the Lagrangian with respect to position is equal to mgl sine theta. Now in this case we get a scalar but if the system had multiple degrees of freedom, we would instead get a vector whenever we take a partial derivative. The partial derivative of the Lagrangian with respect to velocity is equal to ml squared times the angular velocity, and differentiating with respect to time, gives ml squared times the angular acceleration. We get the equations of motion when we combine these two terms and set the result to zero. Notably when we simplify the equations we see that the mass cancels out leading to the interesting result that the frequency that the simple pendulum is unaffected by its mass. The equations in motion for a system resulting from the Euler-Lagrange operator of a nice structure that can be useful to understand.