Dynamic equations for point systems: forces, momenta
We'll start with a single particle moving along a trajectory in the plane. The position of the particle is
. The velocity vector is
.
At any given time, the momentum
of the particle is defined as

The momentum vector is constant unless forces are acting on the particle; the rate of change of momentum is the force:
(2)
Imagine that there is a force field over the plane,
. We have

Given an initial position and velocity for the particle
we could compute the initial acceleration, and integrate the acceleration twice to find the velocity and position of the particle at each time.
Numerical integration of dynamics equations
If the force field is constant (for example, an approximation of a gravitational field near the earth's surface), we might be able to find an analytical solution, but otherwise numerical integration is probably needed.
Euler integration
The simplest choice (but probably not the best choice) is to use Euler integration. For some differential equation
(4)
choose some time step
. Then use a finite difference equation to compute an approximation of
at the next time step:

There is a bit of a problem: we have a second-order differential equation! Folding the constant
into the function f,

We could solve for the velocity at time step 1, and use the velocity from time step 0 to approximate the position at time step 1. Then use the velocity and position from time step 1 to compute the velocity and position at time step 2, etc.
There is a nice trick that lets you write any n-th order differential equation (with n dots over the x) as a first-order differential equation.
Define
. The four-dimensional vector
is called the state of the system, and is composed of the configuration and the velocity of the system. Notice that we have

That is,
, a first-order differential equation. For this reason, numerical integration methods are typically written to solve only first-order differential equations.
Smoother integration techniques: Midpoint, Runge-Kutta
Numerical integration techniques like the Euler-step method rely on the assumption that the force applied to the system (or more generally, the function of state) does not change too rapidly with time.
The Euler method computes the velocity at the beginning of the time step, and assumes this velocity is constant over the entire time step. This is a problem particularly if the velocity is always changing in the same direction. For example, consider the differential equation
(8)
with
. We know this to be the equation of a circle. We will get an outward spiral if we apply the Euler step method, though.
One idea is to compute an estimate of the configuration halfway through the time step (using an Euler approximation), use that configuration to compute the velocity vector, and then use that velocity vector (and the original configuration) to estimate the configuration at the end of the time step. This is called the midpoint method:
(9)
There is a worst-case analysis of Euler and midpoint methods on Wikipedia. It turns out the the expected error of the Euler-step method is
and only
for the midpoint method. Since twice the computation is required for the midpoint method, it would seem that the expected error per unit of computation is similar.
However, notice that the effect of using midpoint instead of Euler is not the same as simply halving the size of the time step. For the circle example, we expect the midpoint method to stay much closer to the actual trajectory, rather than spiralling out as the Euler method does. The "worst-case" curves for the two methods are different.
The idea of the midpoint method is to compute the vector f at a "better" place than at the start of the time step. This idea is taken further by popular Runge-Kutta methods. In RK4, four vectors are computed, and the weighted average is used to compute the result of the time step. For smooth systems, these methods are expected to give much better convergence than midpoint or Euler, per unit of computation.
There are many other numerical integration techniques, designed to solve various classes of differential equations. For example, if the forces on the system are large, we say that the system is stiff. (Imagine a stiff spring, or a piece of cloth with very high forces exerted to keep the cloth from stretching). For these systems, methods like those we have described tend to be unstable — error in position computation leads to large restoring forces, leading to even larger errors on the next time step. Implicit integration techniques tend to be more stable, allowing larger time steps.
Energy and work
In high-school physics, there was a definition of the work done by a particle as the force applied to the particle multiplied by the distance the particle moved. However, we only "count" the amount of force that is parallel to the direction of motion. For example, a particle moving horizontally in a vertical gravitational force field does no work versus gravity.
If the particle is moving along a trajectory, we have the following definition of work:
(10)
Mathworld gives the following definition of a conservative system:
the work done by a force in a conservative system is
- Independent of path.
- Equal to the difference between the final and initial values of an energy function.
- Completely reversible.
Gravitational and electric fields are conservative, and can be written in terms of potential engergy functions, such that the negative gradient of the function gives the direction and manitude of the force at any point. For example, define
to be the potential energy function associated with a gravitaional field. Computing the negative gradient vector
gives
, a downwards gravitational force.
Navigation functions; artificial potential fields
Let's step away from the dynamics problem and consider a robotics application that this formulation inspires: navigation of a point robot among obstacles to a goal. It really has nothing to do with dynamics.
Taking the gradient of a smooth energy function at a point gives a force in a direction. You could imagine an energy function over the configuration space so that obstacles were high energy, free space were lower energy, and the goal was zero energy. The robot simple "rolls downhill" (follows the gradient of the potential function) until it reaches the goal.
Artificial potential fields of this type are a very popular method for obstacle avoidance, in part because of how easy they are to implement. For example, define $d_g$ to be the Euclidean distance of the robot from the goal, and $d_i$ to be the distance from the i-th obstacle. Let
(11)
where the k's are positive constants that force the robot towards the goal or away from obstacles.
V has a unique global minimum at the goal, so we might hope that the robot will reach that minimum by following the gradient. There is a problem, however — the robot may be caught in a local minimum. There are a few solutions to this that people have tried:
- create an escape strategy to get out of local minima
- ensure that there are no local minima
A simple escape stragegy is to cause the robot to thrash randomly when it detects that it is stuck — this is sometimes called "Brownian motion" escape strategy.
There are different ways to ensure that there is only a global minimum. One method is to cause the potential energy function to be the time cost of the fastest path to the goal from each point in the configuration space. Of course, if we could compute that, we wouldn't need a potential energy function! (Notice how comparitively easy the quadratic potential function above is.) We have seen an example of this: the wavefront dynamic programming planner on a grid.
Another approach is to place restrictions on the shapes of the obstacles, and prove that with those restrictions certain simple-to-compute potential functions do not have local minima. This is the approach taken by Koditschek's work on navigation functions.
Kinetic energy
Ok, back to the phsyics. Define the kinetic energy T to be
(12)
where
are the mass and velocity of the i-th particle. In a conservative system, the sum H = T + V, called the Hamiltonian, is conserved (constant). Forces that do work (have a component that is not orthogonal to the velocity of the system) can add or remove energy from a non-conservative system.
The kinetic and potential energies of the system can be used to derive other quantities of interest, including forces and momenta. This is particularly interesting because the energies are scalar quantities and may often be computed in a straightforward way even for complicated systems.
But let's consider first a simple particle in a gravitational field. We have
and
.
First, notice that the momentum of the particle can be computed by taking the partial derivatives of the kinetic energy with respect to the coordinate velocities
and [[\dot y]]:


The force on the particle is the rate of change of the momentum:
(15)
The force can be computed as a gradient of the potential energy:
(16)
So for a particle, we have the equations of motion written in terms of energy.
(17)

That is, the rate of change of momentum (which is the partials of the kinetic energy with respect to the velocity) is a vector along the negative gradient of the potential energy field.
Define the term
, called the Lagrangian of the system. Since
is independent of the position, and
is independent of the velocity, we could write the previous equations as:

where
is the i-th coordinate. What happens if there are external forces? We just put them on the right hand side:

We now have a description of the equations of motion in terms of a single scalar quantity, the Lagrangian, and the external forces. Why should we do such a thing? We will see in the next section that this equation holds even if we write the equations in generalized coordinates. This means we can move from writing three equations per particle to writing a single equation for each freedom (or generalized coordinate) of the system, and do not have to express constraint forces explicitly.
Lagrangian dynamics
For a dynamic mechanical system, we will see that the equations of motion are:
(21)
where
are the external forces applied to particles of the system.
Simple pendulum example
Let's take a simple example of a pendulum with no external forces; all forces are caused by the conservative gravitational potential field. Let the configuration of the pendulum be given by
. We then write expressions for kinetic and potential energy in terms of q:


The Lagrangian is
(24)
We compute the first partial term:
(25)
and the time derivative:
(26)
The partial of L with respect to
:

So the equations of motion are:
(28)
We can simplify and solve for
:


We could numerically integrate to simulate the system, by taking the state to be
and using e.g. RK 4 on the resulting first-order differential equation. Or we solve analytically (not possible for many systems, but this one is simple) to find the trajectories for a simple harmonic oscillator. Or we could analyze what happens to the system if forces are applied by motors or a finger.
Derivation of Lagrangian dynamics equations
There are many ways to derive the Lagrangian formulation, but most of the derivations make use of a somewhat abstract idea called "virtual work" (for example, the Wikipedia article uses this approach). We will return to the idea of virtual work, but for now, I'll give a proof of the Lagrangian equations that is based only on
for particles and the differential kinematics you are already familiar with. The proof is based roughly on Symon's "Mechanics", page 309, published in 1953, but I will use our own vector and matrix notation.
Remember that for particles, the momentum of the system is given by the partial derivatives of the kinetic energy with respect to velocity. The forces are given by the time derivative of that. Therefore, we will start by computing the quantity
(31)
Let
, let
be the diagonal matrix with the first three elements
, next three $[[m_2]]$, etc. Let
be the Jacobian such that
.
First, we need an expression for the kinetic energy of the system.
(32)
Side note: an expression of the form "transpose of a vector times symmetric positive definite matrix times the same vector" is called a quadratic form. Quadratic forms take a vector as input and return a scalar, and the scalar is positive if the vector has non-zero length.
We can also write the kinetic energy as a function of the generalized velocities. Notice that
, so:

This is also a quadratic form, but with the input variable
and a different matrix. The matrix
has a special name; it is called the mass matrix, and we will see it again and again in formulations of dynamics problems. Notice that the size of the square mass matrix is equal to the number of generalized coordinates.

The generalized momentum vector
is the vector of partials of the kinetic energy with respect to each generalized velocity:

It turns out that the vector of partials of a quadratic form with respect to the input vector can be computed simply, if the matrix is independent of the input vector. That is, for any vector
, and any matrix Q that is not a function of y,
. To prove this trick works, just write out all the elements of the vector and matrix and take the partials.

This momentum is entirely analogous to the one-dimensional case: momentum is the product of mass and some velocity — in this case, our mass matrix is a bit more complicated because of the "change of coordinates" by the Jacobian.
Now we want to look at the rate of change of the momenta. Let's go back to talking about the motion of particles rather than generalized coordinates. We have:
(37)
If we take the time derivative, we get:
(38)
From Newton's laws, if the forces applied to the particles are
, then
, so we have

The term
can be thought of as the effect that forces applied at the particles has on the "joints". In fact, these terms have a special name, the generalized forces, and sometimes are given the symbol
. A torque is an example of generalized force; the torque is actually caused by forces applied at points, but the net effect is an angular acceleration
.
But there's this other term:
. I don't have a good proof in vector notation, but if you write out all the terms in the matrix multiplication, you can show that
.
We therefore have:
(40)
where the generalized force
has components due to external forces and due to the gradient of the potential energy.

This is a slightly alternate form of the Lagrangian equations in the last section.
Standard form for dynamics equations
Remember that the generalized momentum can be written as
(42)
The dynamics equations are
(43)


Without going into the details, the term
turns out to be a matrix mutliplied by
. The form of the equations is then

Rigid bodies
The generalized coordinates for a rigid body are usually chosen to be the location of some reference point on the body, as well as additional coordinates to express the rotation of the body. It therefore turns out that the generalized forces have a translational component (the net force on the body) and a component that affects angular acceleration (the net torque on the body). The mass matrix and kinetic energy also have a special structure:
(47)
where
is the 3-vector giving the rotational velocity, and
is a matrix called the inertia tensor. The inertia tensor depends on the configuration of the body, but is constant when viewed in the body frame. Paritosh found this excellent set of notes describing further properties of the inertia tensor: The Inertia Tensor and After Dinner Tricks, by Steve Drasco.





