In this system there is a wheeled cart moving along a horizontal track. From the cart a pendulum is suspended. A spring is attached to the cart as shown.

There are two ways to find the equations of motion for a system like this, the direct Newtonian way or the indirect Lagrangian way. We show both methods here.

For both direct and indirect methods, we first need to get the kinematics right. Kinematics means the relations of the parts of the device, without regard to forces. In kinematics we are only trying to find expressions for the position, velocity, & acceleration in terms of whatever variables we have chosen.

The variables we choose here are:

x = position of cart (0 = spring unstretched)θ = angle of pendulum (0 = pendulum hanging straight down)R = length of rod (constant)

We'll need the standard unit vectors, **i**,**j**

unit vector in horizontal direction**i**= unit vector in vertical direction**j**=

The kinematics for the cart are simple

**i**

velocity = x' **i**

acceleration = x'' **i**

The kinematics for the pendulum are more complex.

**i** + R sin θ **i** - R cos θ **j**

velocity = x' **i** + R θ' cos θ **i** + R θ' sin θ **j**

acceleration = x'' **i** + R θ'' cos θ **i** ^{2} sin θ **i** **j** ^{2} cos θ **j**

The position is derived by a fairly simple application of trigonometry. The velocity and acceleration are then just the first and second derivatives of the position.

We treat the cart and the pendulum bob as point particles. Begin by drawing the free body diagram for the cart and writing an expression for the net force acting it.

The variables are as follows

N = normal force (from the track the cart is on)T = tension in the rodM = mass of cartm = mass of pendulumg = gravitational constant

The forces on the cart are the spring force **i****j****j****j** + T sin θ **i**

**F** = N **j** - M g **j** - T cos θ **j** + T sin θ **i** - k x **i**

Now using Newton's law **F** = m **a**

**j** - M g **j** - T cos θ **j** + T sin θ **i** - k x **i** = M x'' **i** (eqn 1)

Next we draw the free body diagram for the pendulum. The forces on the pendulum are the tension in the rod and gravity. So we can write the net force as:

**F** = T cos θ **j** - T sin θ **i** - m g **j**

Using Newton's law **F** = m **a**

**j** - T sin θ **i** - m g **j** = **i** + R θ'' cos θ **i** ^{2} sin θ **i**
**j** ^{2} cos θ **j**) (eqn 2)

Now we can write the vector components of the above equations 1 & 2 as separate equations. This gives us 4 simultaneous equations.

N - M g - T cos θ = 0

- T sin θ = m(x'' + R θ'' cos θ - R θ'^{2} sin θ) (eqn 4)

T cos θ - m g = m(R θ'' sin θ ^{2} cos θ) (eqn 5)

Now we do some algebraic manipulations to eliminate the unknown tension

^{2} sin θ

(M + m)x'' = m R θ'^{2} sin θ - m R θ'' cos θ - k x (eqn 6)

Multiply equation 5 by

^{2} θ ^{2}sin θ cos θ

Use equation 4 to replace

^{2}θ ^{2}sin θ cos θ ^{2}θ ^{2}sin θ cos θ

This simplifies to

^{2}θ ^{2}θ

Using the trig identity ^{2}θ + sin^{2}θ = 1

x''cos θ + R θ'' + g sin θ = 0 (eqn 7)

Equations 6 and 7 are the equations of motion. We have two equations in the two variables

^{2} sin θ - m R θ'' cos θ - k x (eqn 6)

x''cos θ + R θ'' + g sin θ = 0 (eqn 7)

We will need to do some further manipulations of these two equations to get them into a form suitable for the Runge-Kutta numerical analysis method (see below).

The indirect method is based on the energy of the system. In the current example there are no non-conservative forces (ie. no friction or damping) so we get to skip some steps. Our first step is to find the Lagrangian of the system which is the kinetic energy minus the potential energy.

L = T - V

L = the LagrangianT = kinetic energyV = potential energy

For the kinetic energy we need the velocity of the cart and pendulum, which we calculated earlier
(see kinematics above). Kinetic energy is given by **v**^{2}**v**^{2} = **v**·**v**

**i**)^{2} **i** + R θ' cos θ **i** + R θ' sin θ **j**)^{2}

Applying the dot product rule to square the vectors we get

^{2} ^{2} + (R θ' sin θ)^{2})

There are two stores of potential energy in this system: the spring and the gravitational potential of the pendulum.

V_{spring} = (1/2)k x^{2}

V_{gravity} = m g height = m g(R - R cos θ)

So the Lagrangian for the system is

^{2} ^{2} ^{2}
^{2}

Next we will derive the equations of motion from Lagrange's Equation. For the

0 =

Note that

L = M x' + m(x' + R θ' cos θ)

L = - k x

Taking the derivative with respect to time of

^{2} sin θ

which we can rearrange to be identical to the corresponding equation found above in the direct method

^{2} sin θ - m R θ'' cos θ - k x (eqn 6)

Here again is the Lagrangian for the system:

^{2} + ^{2} ^{2} ^{2}

For the

0 =

Here are the partial derivatives:

^{2} sin^{2}θ

L = -m(x' + R θ' cos θ)R θ' sin θ ^{2} θ'^{2}sin θ cos θ

Note that we can divide out the constant

^{2} sin θ)cos θ ^{2}θ ^{2}R sin θ cos θ ^{2}sin θ cos θ

We can fully expand this to

^{2}θ ^{2}sin θ cos θ ^{2}sin θ cos θ
^{2}θ ^{2}sin θ cos θ ^{2}sin θ cos θ
^{2}sin θ cos θ

After lots of cancellations and using the identity ^{2}θ + cos^{2}θ = 1

x''cos θ + R θ'' + g sin θ = 0 (eqn 7)

To solve the equations of motion numerically, so that we can drive the simulation, we use the Runge-Kutta method for solving sets of ordinary differential equations.

To use the Runge-Kutta method, we need to get equations 6 and 7 into the following form:

x'' = f(x, x', θ, θ')

θ'' = g(x, x', θ, θ')

where

^{2} sin θ - m R θ'' cos θ - k x (eqn 6)

x''cos θ + R θ'' + g sin θ = 0 (eqn 7)

Here are the manipulations needed to get these equations into the desired form. First we rearrange equations 6 and 7 to the following:

^{2} sin θ - m R θ'' cos θ

θ'' = -x''cos θ/R - (g/R) sin θ (eqn 9)

Substitute equation 9 into equation 8 and then solve for

^{2} sin θ

(M + m - m cos^{2}θ)x'' = m R θ'^{2} sin θ

m R θ' |

Substitute equation 8 into equation 9 and solve for

cos θ[m R θ' |

^{2}θ ^{2} sin θ cos θ

m R θ' |

-m R θ' |

Equations 10 and 11 are now close to the form needed for the Runge-Kutta method. The final step is convert these two 2nd order equations into four 1st order equations. First we define the first derivatives as separate variables:

v = velocity of cartω = angular velocity of pendulum

Then we can write the four 1st order equations:

x' = v

θ' = ω

m R ω |

-m R ω |

This is now exactly the form needed to plug in to the Runge-Kutta method for numerical solution of the system.