Let original length of pendulum be \(L\) and extension at instance shown be \(u\). The inertial frame has unit vectors \(\hat {I},\hat {J},\hat {K}\). The cart moves horizontally only and at instance shown is moving in positive direct at distance \(X\) from origin. Let unit vectors for the body frame be \(\hat {\imath },\hat {\jmath },\hat {k}\).
The bob has three degrees of freedom. In other words, to locate the bob at any time, we need to know \(X,\theta ,u\,\) where \(X\) is the horizontal displacement of the cart, \(\theta \) is the angle the pendulum spring makes with the vertical and \(u\) is the amount of extension of the spring. So will end up with three equations of motion, one for each degree of freedom.
We always start by finding the position vector of bob which is
For help with the sign used for cross product between vector, this diagram is used.
For example \(\hat {k}\times \hat {\imath }=\hat {\jmath }\) since the motion is counter clockwise hence positive. While \(\hat {k}\times \hat {\jmath }=-\hat {\imath }\) since motion was negative.
Now we can find the acceleration of the bob in inertial frame using the above result as follows
To express \(\hat {I},\hat {J}\) in terms of body basis \(\hat {\imath },\hat {\jmath }\) or to expression body basis \(\hat {\imath },\hat {\jmath }\) in terms of inertial basis \(\hat {I},\hat {J}\) we will use the following diagram
So far, we have found 4 equations. They are (6,7,8,9), But we have 5 unknowns, they are \(\ddot {\theta },\ddot {X},R_{1},R_{2},\ddot {u}\). We need one more equation. Typically this is the moment equation. Taking moments around point \(A\) where pendulum is attached. This gives (using \(\tau =I\ddot {\theta }\,\) where \(I=mL^{2}\) for point mass pendulum, and here \(L\equiv \left ( L+u\right ) \) to account for the extension, which is the current length of pendulum). Hence moment equation for the pendulum
is
Where \(R_{1},R_{2}\) are given by (11,12). This completes the solution.
Numerically we can now solve the above using some numerical values for \(g,k_{1},k_{2},c,m,M,L,L_{0}\) and with 6 initial conditions for \(u\left ( 0\right ) ,u^{\prime }\left ( 0\right ) ,X\left ( 0\right ) ,X^{\prime }\left ( 0\right ) ,\theta \left ( 0\right ) ,\theta ^{\prime }\left ( 0\right ) \) and run the simulation showing the motion. The force \(F\) on the cart, can be anything we want. For an example \(F=\sin t\) or it can be zero also (but now we have to give the cart some non zero initial position or non zero initial velocity to make it move).
If we did not have a cart at the top, and the pendulum was hinged on a fixed point at the top, then now \(\ddot {X}=0\) and \(R_{1}=R_{2}=0\) and the above 3 equations reduce to two only (since we have lost one degree of freedom)
In addition, if we did not have a spring, but a normal bob pendulum on massles rod, then \(u=0\) now and the above two equations reduce to only one (since we lost one more degree of freedom \(u\)). This results in the standard pendulum equation of motion
\[ \ddot {\theta }+\frac {g}{L}\sin \theta =0 \]
Numerical simulation of motion can be now done using (13,14,15).