Introduction
Philosophy
The point of a model is to synthesize the real world and predict future behavior. It is often an added bonus that the mathematical representations offer additional viewpoints. It is important to point out that time spent modeling is not always beneficial. Direct experimentation is often faster and can provide more intuitive results. Furthermore, a model is only as good as the observations that it is based upon. Where do those observations come from? Experimentation!
So if experimentation is so great why model at all? Two reasons: 1) Nondestructive testing and 2) Interpolation. Many times the experiment required to answer a particular result would destroy the object in question. Collapsing a bridge by driving an overloaded semitruck on it is far less expensive in computer simulation than in reallife and also less traumatic for the truck driver. Also, it can be expensive and time consuming to take many measurements that could be generated by a model. A simple example of this is curvefitting, where a curve is fit to experimental results. Once the curve has been fit, you can use it to interpolate values that were not explicitly measured.
My model will hopefully be used for both nondestructive testing and interpolation of experimental results. I don't have IRB approval to cutopen someone's head and look at their brain while they try to stand upright, so hopefully I can metaphorically do that to my model. Furthermore, I hope that the model fits the experimental data so that I can use it to interpolate recorded data.
Modeling Goal
The doublependulum model is a simplified model of the
anteriorposterior motion of a standing human. This simulation mimics
an experimental protocol where a subject is placed on a translational
platform. The platform movement is sudden, causing a disturbance
similar to the sudden start/stop of a subway car to the standing
subject. Examining the patterns of muscle activation and motion of the
body helps to reveal how the nervous system interacts with the
musculoskeletal system. In this dynamical model the links of the pendulum will approximate the legs and trunk of a human subject. An acceleration to the inertial frame will be applied to represent the
disturbance caused by the translational platform.
Algorithm
There are many methods of developing "dynamical" models. However, to be successful with any technique requires an initial intuition about the motion of the system, development of kinematic relations and the analysis of forces. The following algorithm works pretty well for a fairly wide range of simple systems and for the most part removes the requirement for having to remember the subtleties of mechanics.
 Draw a sketch of system and think about how it moves.
 Determine degreesoffreedom (DOF) of system: number of variables you would need to locate the object in space
 Define coordinate systems: an inertial frame is always required
 Pick generalized coordinates: these are the variables that describe the DOF
 Work out position vectors from the origin of the inertial frame to the centerofmass (COM) for all of your rigid bodies.
 Take the first derivative of all of your position vectors.
 Identify all of the kinetic and potential energy.
 Employ Lagrange's equations.
 Apply external forces with virtual work.
Kinematics
Sketch

 θ1  angular position of first link
 θ2  angular position of second link
 L1  length of first link
 L2  length of second link
 m1  mass of first link
 m2  mass of second link

Degreesoffreedom & Coordinates
The two planar links each have two translational and one rotational DOF and are constrained by two pin joints, which limit the translational DOF. Therefore the double pendulum system has two degrees of freedom.
A single planar cartesian coordinate system is all that is necessary to define the inertial coordinate frame. Generalized coordinates describing the motion can be selected by specifying the rotation of the first link with respect to the
inertial frame and the second link's rotation relative to the first
link. Specifying the second link with a relative coordinate poses
additional complexity, but makes it more intuitive when it comes time
to implement control.
Position
We are interested in first finding the position vectors for the centerofmass for link 1 and 2, defined by points A and B. Those vectors are as follows:
(1)


(2) 

Velocity
The derivatives of the position vectors give us the velocity for the COMs for the two links. This will be useful for quantifying the amount of kinetic energy stored in the moving links.
It is also advantageous to write out the squared velocities at this time as they will be needed for further calculations.
Dynamics
Energy
The kinetic energy for the system can be found by summing the linear and rotational components for each rigid body. A point of interest is that the rotational kinetic energy of the second link depends on the rotational velocity of itself and the first link. This is because of how the generalized coordinates were selected.
The potential energy for the system is quantified by the change in COM within a gravitational field.
(8) 

In order to correctly apply a perturbation to the double pendulum as if the ground was accelerated from sidetoside, we can pull a small trick. Since such a perturbation would act as an acceleration to the inertial frame we can compute the "potential" within this frame. We will call this applied acceleration x'' (here double prime = double dot = second derivative).
(9) 

Lagrange
We now formulate the lagrangian using Eqs. 7, 8 and 9.
Then using the lagrangian formula (Eq 11) we compute the equations of motion.
The result is two equations, one for each DOF. Equation 12 for θ1 and Eq 13 for θ2.
Applied Forces
Torque is applied at each of the joints and written as T1 and T2. To find the generalized forces associated with these torques we first compute the virtual work of the system. To help with determining the virtual work pretend that all the joints are locked except for one and imagine the work that would be associated with that DOF, then go on to the next generalized coordinate.
From here we can recognize the generalized forces as those associated with the virtual increments of the generalized coordinates.
Equations of Motion
Finally, we can write the equations of motion in a compact form as shown in Eq 17. Note that
q'' is a vector holding θ1'' and θ2''. Furthermore
M is the mass matrix, which is symmetric and positive definite. This ensures that the mass is always positive and real valued.
F is the portion of the equations of motion associated with coriolis and gravitational forces.
Q is the vector containing the generalized forces and
P is the vector containing the transformation for the perturbation acceleration x".
Attached at the bottom of this page are Matlab files for
symbolic manipulation and
numeric computation for these equations of motion. A simulation of these equations can be found
here.