Theory

There are two forces acting on the standing rod: gravity and the motion of the cart. This analysis assumes the "pendulum" is actually a rod with equal mass all along its length.

Gravity

Gravity acts all along the length of the beam, providing an equal force all along the beam.

F = ρ*L*g

where ρ is the linear density of the beam (mass per distance), L is the length of the beam, g is the acceleration of gravity, and a is the angle deviation from vertical.

This force provides a torque (T = Fperp*L where Fperp is the component of the force perpendicular to the beam, Fperp = F*sin(a)).

Tgravity = 0.5*ρ*L2*g*sin(a)


Cart Motion

Independent of gravity, the motion of the cart to which the pendulum is attached will provide a force on the pendulum.

F = ρ*L*x''

Which results in a torque:

Tmove = 0.5*ρ*L2*cos(a)*x''


Total

The total torque on the standing rod is given by the sum of these torques. Because T=I*a'' (I = ρ*L3/3), this allows us to write the ultimate governing equation:

a'' = (3/2*g*sin(a) + x''*cos(a))/L