### MyPhysicsLab – Pendulum+Cart

vertical:    horizontal: graph type:

#### Physics

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.

#### Kinematics

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. We use bold and overline to indicate a vector.

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

The kinematics for the cart are simple

position = x i
velocity = x' i
acceleration = x'' i

The kinematics for the pendulum are more complex.

position = x i + R sin θ i - R cos θ j
velocity = x' i + R θ' cos θ i + R θ' sin θ j
acceleration = x'' i + R θ'' cos θ i - R θ'2 sin θ i + R θ'' sin θ j + R θ'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.

#### Direct Method for Finding Equations of Motion

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 rod
• M = mass of cart
• m = mass of pendulum
• g = gravitational constant

The forces on the cart are the spring force -k x i, the normal force N j, gravity -M g j and the tension in the rod -T cos θ j + T sin θ i. The net force on the cart is the sum of these

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

Now using Newton's law F = m a and the cart acceleration we found earlier, we have

N 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 and the pendulum acceleration we found earlier, we have

T cos θ j - T sin θ i - m g j = m(x'' i + R θ'' cos θ i - R θ'2 sin θ i + R θ'' sin θ j + R θ'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.

T sin θ - k x = M x''    (eqn 3)
N - M g - T cos θ = 0
- T sin θ = m(x'' + R θ'' cos θ - R θ'2 sin θ)    (eqn 4)
T cos θ - m g = m(R θ'' sin θ + R θ'2 cos θ)    (eqn 5)

Now we do some algebraic manipulations to eliminate the unknown tension T. Combining equations 3 and 4 we get:

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

Multiply equation 5 by sin θ

T sin θ cos θ - m g sin θ = m R θ'' sin2 θ + m R θ'2sin θ cos θ

Use equation 4 to replace T sin θ.

-m x''cos θ - m R θ''cos2θ + m R θ'2sin θ cos θ - m g sin θ = m R θ'' sin2θ + m R θ'2sin θ cos θ

This simplifies to

m x''cos θ + m R θ''cos2θ + m R θ'' sin2θ + m g sin θ = 0

Using the trig identity cos2θ + sin2θ = 1 this becomes

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 x,θ and their derivatives. Here they are together for future reference:

(M + m)x'' = m R θ'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).

#### Indirect (Energy) Method for Finding Equations of Motion

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 Lagrangian
• T = kinetic energy
• V = 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 (1/2)m v2. Note that we use the vector dot product to square a vector, v2 = v·v. So we have

T = (1/2) M (x' i)2 +(1/2) m (x' i + R θ' cos θ i + R θ' sin θ j)2

Applying the dot product rule to square the vectors we get

T = (1/2) M x'2 + (1/2) m ((x' + R θ' cos θ)2 + (R θ' sin θ)2)

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

Vspring = (1/2)k x2
Vgravity = m g height = m g(R - R cos θ)

So the Lagrangian for the system is

L = (M/2)x'2 + (m/2)(x' + R θ' cos θ)2 + (m/2)(R θ' sin θ)2 - (k/2)x2 - m g R(1 - cos θ)

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

0 =

Note that x' and x are treated as separate variables when taking partial derivatives. Here are the partial derivatives:

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

Taking the derivative with respect to time of L and subtracting L we have

0 = = M x'' + m x'' + m R θ'' cos θ - m R θ'2 sin θ + k x

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

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

Here again is the Lagrangian for the system:

L = (M/2)x'2 + (m/2)(x' + R θ' cos θ)2 +(m/2)(R θ' sin θ)2 -(k/2)x2 -m g R(1-cos θ)

For the θ variable Lagrange's Equation is

0 =

Here are the partial derivatives:

L = m(x' + R θ' cos θ)R cos θ + m θ' R2 sin2θ
L = -m(x' + R θ' cos θ)R θ' sin θ + m R2 θ'2sin θ cos θ - m g R sin θ

Note that we can divide out the constant m R   from both of the partial derivatives. Taking the derivative with respect to time of L and subtracting L we have

0 = = (x'' + R θ'' cos θ - R θ'2 sin θ)cos θ - θ' sin θ(x' + R θ' cos θ) + θ'' R sin2θ + 2 θ'2R sin θ cos θ +(x' + R θ' cos θ)θ' sin θ - R θ'2sin θ cos θ + g sin θ

We can fully expand this to

0 = x'' cos θ + R θ'' cos2θ - R θ'2sin θ cos θ - x' θ' sin θ - R θ'2sin θ cos θ + θ'' R sin2θ + 2 R θ'2sin θ cos θ + x' θ' sin θ + R θ'2sin θ cos θ - R θ'2sin θ cos θ + g sin θ

After lots of cancellations and using the identity sin2θ + cos2θ = 1, we have the same result as from the direct method (above)

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

#### Numerical Solution

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 f,g are functions to be determined. So we want to solve for each second derivative in terms of lower derivative variables. Here again are equations 6 and 7, and you can see that they don't yet fit the above form because there are 2nd derivatives on the right-hand sides.

(M + m)x'' = m R θ'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:

x'' = [m R θ'2 sin θ - m R θ'' cos θ - k x]/(M + m)    (eqn 8)
θ'' = -x''cos θ/R - (g/R) sin θ    (eqn 9)

Substitute equation 9 into equation 8 and then solve for x'':

(M + m)x'' = m R θ'2 sin θ + m R cos θ(x''cos θ/R + (g/R) sin θ) - k x
(M + m - m cos2θ)x'' = m R θ'2 sin θ + m g cos Qsin θ - k x

 m R θ'2 sin θ + m g cos θ sin θ - k x x'' = —————————————————————————————————————    (eqn 10) M + m sin2θ

Substitute equation 8 into equation 9 and solve for θ'':

 cos θ[m R θ'2 sin θ - m R θ'' cos θ - k x] -R θ'' = —————————————————————————————————————————— + g sin θ M + m

-R(M+m)θ'' + m R θ'' cos2θ = m R θ'2 sin θ cos θ - k x cos θ + g(M+m)sin θ

 m R θ'2sin θ cos θ - k x cos θ + g(M + m)sin θ θ'' = —————————————————————————————————————————————— -R(M+m) + m R cos2θ
 -m R θ'2sin θ cos θ + k x cos θ - g(M + m)sin θ θ'' = ———————————————————————————————————————————————    (eqn 11) R (M + m sin2θ)

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 ω2 sin θ + m g cos θ sin θ - k x v' = —————————————————————————————————————    (eqn 10) M + m sin2θ
 -m R ω2 sin θ cos θ + k x cos θ - g(M + m)sin θ ω' = ———————————————————————————————————————————————    (eqn 11) R (M + m sin2θ)

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