The Mathmatica Notebook is here.

Work out the Lagrangian equations of motion for an inverted pendulum on a
moving base.

m1 mass of block

m2 mass of pendulum

l length of pendulum

x[t] position of m1

φ[t] angle of pendulum 0 is down

g force of gravity

Fx[t] the force we apply to the m1.

Fφ[t] the tangential force we apply to m2.

By inspection we find the  Lagrangian

[Graphics:Images/ip_math_gr_1.gif]
[Graphics:Images/ip_math_gr_2.gif]
[Graphics:Images/ip_math_gr_3.gif]
[Graphics:Images/ip_math_gr_4.gif]

We use x2 and y2 as the x and y position of m2 - now we need x2 and y2 in
terms of x, l and φ.

[Graphics:Images/ip_math_gr_5.gif]
[Graphics:Images/ip_math_gr_6.gif]
[Graphics:Images/ip_math_gr_7.gif]
[Graphics:Images/ip_math_gr_8.gif]
[Graphics:Images/ip_math_gr_9.gif]
[Graphics:Images/ip_math_gr_10.gif]
[Graphics:Images/ip_math_gr_11.gif]
[Graphics:Images/ip_math_gr_12.gif]

Now to get the Lagrangian equations of motion.

[Graphics:Images/ip_math_gr_13.gif]
[Graphics:Images/ip_math_gr_14.gif]
[Graphics:Images/ip_math_gr_15.gif]
[Graphics:Images/ip_math_gr_16.gif]
[Graphics:Images/ip_math_gr_17.gif]
[Graphics:Images/ip_math_gr_18.gif]
[Graphics:Images/ip_math_gr_19.gif]
[Graphics:Images/ip_math_gr_20.gif]
[Graphics:Images/ip_math_gr_21.gif]
[Graphics:Images/ip_math_gr_22.gif]
[Graphics:Images/ip_math_gr_23.gif]
[Graphics:Images/ip_math_gr_24.gif]
[Graphics:Images/ip_math_gr_25.gif]
[Graphics:Images/ip_math_gr_26.gif]
[Graphics:Images/ip_math_gr_27.gif]
[Graphics:Images/ip_math_gr_28.gif]
[Graphics:Images/ip_math_gr_29.gif]
[Graphics:Images/ip_math_gr_30.gif]