Analysis of Pendulum-cart system and newtonian physics.
In modern Newtonian physics reside two of the most important and widely used mechanical systems; that is, pendulums and springs. Nowadays these systems are ubiquitous in our modern world, appearing in a vast number of mechanical systems such as clocks, car suspensions, metronomes, mattresses, and shock absorbers. The influence these two mechanical systems have had in our everyday life motivates their further study. Thus, B.R.I.T decided to study and model a pendulum-cart mechanism by utilizing equations of motion, free body diagrams, differential equations, and python for a numerical and graphical solution of the system.
Content
- 5) Conclusion
1. What is a pendulum-cart system
A pendulum-cart system consists of a cart moving in a horizontal trajectory while being attached to a spring on a wall. Thus, converting the cartβs linear motion into a back-and-forth pattern like that of a simple harmonic oscillator. Additionally, a pendulum is suspended from the cart which will move in response to the cartβs motion.
1.1 Axis and parameter set up
Before we can analyse the system, certain parameters and axis must be chosen. To simplify things, an < π₯, π¦, π§ > axis was chosen such that the diagram looks as follows. Here, βπ§β is an important axis because of the torqueβs direction.
- X = position of the cart (m)
- L = Length of the pendulum rod (m)
- Ο΄ = Angle of pendulum (rad)
1.2 Free-body diagram
To further our understanding of the system, we will determine all forces acting on it by creating a free-body diagram to both the pendulum and the cart.
Free-body diagram for the pendulum

m = mass of pendulum (kg)
g = gravitational constant (9.8m/s2)
ΞΌ1 = friction coefficient pendulum
T = tension (N)
βΊ = friction force (N)
mg = force due to gravity (N)

the force that creates the torque βπβ can be represented as a force ββΊβ acting on both the pendulum and the cart (because of newtons 3rd law). If we take into consideration this new force ββΊβ and the length of the rod βLβ as a vector, then we could find the torque by computing a cross product between them.
Free-body diagram for the cart

M = mass of the cart (kg)
g = gravitational constant (9.8m/s2)
ΞΌ2 = friction coefficient cart
v = velocity (m/s)
k = Spring constant (N/m)
T = tension (N)
βΊ = friction force (N)
mg = force due to gravity (N)
N = normal force (N)
2. Newton’s second law for the pendulum
Applying Newton’s second law will allow us to further examine the mechanics of the system. However, one must first establish certain mathematical relationship between the cart and the pendulumβs position. To do so, we will relate the cartβs position βπ₯β with the pendulumβs position in both < π₯, π¦, 0 > direction which we will call βπ β and βπ β respectively. Ultimately, this relationship will allow us to relate their second derivative with Newton’s second law.

π₯π = π₯ + πΏπ ππ(π)
πp = βπΏπππ (π)
π₯β²π = π₯β² + πβ²πΏπππ (π)
πβ²π = πβ²πΏπ ππ(π)
π₯β²β²π = π₯β²β² + πΏ[πβ²β² cos(π) β (πβ²)2 sin(π)]
πβ²β²π = πβ²β²πΏπ ππ(π) + (πβ²)2Lcos (π)
Newtonβs second law states that the force is equal to the mass times its acceleration.
Thus, in the < π₯, 0,0 > direction we have the following equation.

βπΉπππππ π₯ πππππ’ππ’π = πππ π βπππππππππ‘πππx
βππ ππ(π) β 1/L[π1 πcos (π)] = π β π₯β²β²
i) βππ ππ(π) β 1/L[π1 πβ²cos (π)] = π β [π₯β²β² + πΏ(πβ²β² cos(π) β (πβ²)2 sin(π))]
βπΉπππππ π¦ πππππ’ππ’π =πππ π βπππππππππ‘ππππ¦
π‘πππ (π) β ππ β 1/L[π1 ππ ππ (π)] = π β π¦β²β²
ii) ππππ (π) β ππ β 1/L[(π1)πβ² π ππ(π)] = π β [πβ²β²πΏπ ππ(π) + πΏ(πβ²)2cos (π)]
2.1 Newton’s second law for the cart
Here, we will follow the same steps as before, but this time will apply them to the cart. This will give us the equations of motion for the cart. Clearly, the cart will have no acceleration on < 0, π¦, 0 > direction.

βπΉπππππ π₯ ππππ‘ = πππ π βπππππππππ‘ππππ₯
βππ₯ β π2π£ + ππ ππ(π) + 1/L[π1 πcos (π)] = M β π₯β²β²
iii) ππ ππ(π) + 1/L[π1πβ²cos(π)] β ππ₯ β π2π₯β² = πβπ₯β²β²
βπΉπππππ π¦ ππππ‘ =πππ π βπππππππππ‘ππππ¦
π + (π1 πβ²cos (π))/L β ππ β ππππ (π) = 0
3. Equations of motion
Clearly, there are three main equations derived from Newtonβs second law. There are two equations from the pendulum βi)β and βii)β, and only one equation from the cart βiii)β since the cart has no acceleration in the < 0, π¦, 0 > direction.
i) βππ ππ(π) β 1/L[π1 πβ²cos (π)] = π β [π₯β²β² + πΏ(πβ²β² cos(π) β (πβ²)2 sin(π))]
ii) ππππ (π) β ππ β 1/L[(π1)πβ² π ππ(π)] = π β [πβ²β²πΏπ ππ(π) + πΏ(πβ²)2cos (π)]
iii) ππ ππ(π) + 1/L[π1πβ²cos(π)] β ππ₯ β π2π₯β² = πβπ₯β²β²
If we were to add equation βi)β and βiii)β together we would be creating, and simplifying, a new equation which we will call βiv)β as such.
βππ ππ(π) β 1/L[π1 πβ²cos (π)] + ππ ππ(π) + 1/L[π1πβ²cos(π)]β ππ₯ β π2π₯β² = [ π β [π₯β²β² + πΏ(πβ²β² cos(π) β (πβ²)2 sin(π))] ] + [πβπ₯β²β²]
β ππ₯ β π2π₯β² = π₯β²β² (m + M) + Lm(πβ²β² cos(π) – (πβ²)2 sin(π))
iv) π₯β²β² (m + M)+ ππ₯ + π2π₯β² = Lm((πβ²)2 sin(π) – πβ²β² cos(π))
This new equation βiv)β is particularly useful because it removes the unknown tension βTβ from one of the equations. Thus, leaving us with the following two formulas.
ii) ππππ (π) β ππ β 1/L[(π1)πβ² π ππ(π)] = π β [πβ²β²πΏπ ππ(π) + πΏ(πβ²)2cos (π)]
iv) π₯β²β² (m + M)+ ππ₯ + π2π₯β² = Lm((πβ²)2 sin(π) – πβ²β² cos(π))
However, we still have tension βπβ as an unknown variable in equation βππ)β. To get rid of it, one can multiply βi)β by cos (π) and βii)β by sin (π) and add them together, we will call this new equation βv)β.
[i)βcos(ΞΈ)]
βππ ππ(π)cos (π) β 1/L[π1 πβ²cos2(π)] = ππ₯β²β²cos (π) + πΏππβ²β² cos2(π) β πΏπ(πβ²)2 sin(π) cos (π)
[ii)βsin(ΞΈ)]
ππ ππ(π)πππ (π) β ππ β sin (π) β 1/L[π1 πβ² π ππ2(π)] = πΏππβ²β²π ππ2(π) + πΏπ(πβ²)2sin (π)cos (π)
[i)βcos(ΞΈ)]+ [ii)β sin(ΞΈ)]
β 1/L[π1]πβ²(π ππ2(π) + cos2(π)) β ππ β sin(π) = πΏππβ²β²[π ππ2(π) + cos2(π)] + ππ₯β²β² cos(π)
v) β1/Lπ1 πβ² β ππ β sin(π) = πΏππβ²β² + ππ₯β²β² cos(π)
Finally, we are left with two equations without the tension variable βπβ.
iv) π₯β²β²(π + π) + ππ₯ + π2π₯β² = πΏπ[(πβ²)2 sin(π) β πβ²β² cos(π)]
v) β1/Lπ1 πβ² β ππ β sin(π) = πΏππβ²β² + ππ₯β²β² cos(π)
3.1 Solving second derivative in terms of lower derivative variables
Clearly, βiv)β and βv)β are equations in terms of first and second derivatives of the angle and position. However, before we can transform them as two first order DEβs, we would first need to write πβ²β² and π₯β²β² in terms of lower derivative variables that is π, πβ² and π₯, π₯β². To do so, we need to multiply equation βv)β by cos (ΞΈ) and add equation βiv)β thereby eliminating πβ²β² from the equation. Then, solving for π₯ββ will input a new equation which we will call βvi)β.
[v)βcos(ΞΈ)]
β 1/L[π1 πβ²cos (π)] β ππ β sin(π)cos (π) = πΏππβ²β²cos (π) + ππ₯β²β² cos2(π)
[v)βcos(ΞΈ)]+[iv)]
π₯β²β²(π + π) + ππ₯ + π2π₯β² β 1/L[π1 πβ² cos(π)] β ππ β sin(π) cos(π) = ππ₯β²β² cos2(π) + πΏπ(πβ²)2 sin(π)
π₯β²β²(π + π) β ππ₯β²β² cos2(π) = πΏπ(πβ²)2sin(π) + ππ β sin(π)cos(π) + 1/L[π1 πβ² cos(π)] β ππ₯ β π2π₯β²
π₯β²β²[(π + π) β π cos2(π)] = πΏπ(πβ²)2 sin(π) + ππ β sin(π) cos(π) + 1/L[π1 πβ² cos(π)] β ππ₯ β π2π₯β²
π₯β²β² = [ πΏπ(πβ²)2 sin(π) + ππ β sin(π) cos(π) + 1/L[π1 πβ² cos(π)] β ππ₯ β π2π₯β² ] / [ (π + π) β π cos2(π) ]
π₯β²β² = [ πΏπ(πβ²)2 sin(π) + ππ β sin(π) cos(π) + 1/L[π1 πβ² cos(π)] β ππ₯ β π2π₯β² ] / [(π + π) β π (1 + sin2(π))]
π₯β²β² = [ πΏπ(πβ²)2 sin(π) + ππ β sin(π) cos(π) + 1/L[ π1 πβ² cos(π)] β ππ₯ β π2π₯β² ] / [π + m β sin2(π)]
Now, we can multiply equation βv)β by (π + π) and multiply equation βiv)β by π β cos (π) and add them together thereby allowing the isolation of πβ²β² in one single equation which we will call βvii)β.
[v)β(m+M)]
(π+π)β1/L[βπ1πβ² βππβsin(π)] = (π+π)πΏππβ²β² +ππ₯β²β²(π+π)cos(π)
[iv) β mcos(ΞΈ)]
ππ₯β²β²(π + π)cos (π) + ππ₯πcos (π) + π2π₯β²cos (π) = πΏπ2(πβ²)2 sin(π)cos (π) β πΏπ2πβ²β² cos2(π)
[v)β(m+M)] + [iv)βmcos(ΞΈ)]
β(π + π)1/L( π1 πβ²) β (π + π)ππ β sin(π) + ππ₯π cos(π) + π2π₯β²cos (π) = (π + π)πΏππβ²β² + πΏπ2(πβ²)2 sin(π)cos (π) β πΏπ2πβ²β² cos2(π)
β(π + π)1/L( π1 πβ²) β (π + π)ππ β sin(π) + ππ₯π cos(π) + π2π₯β²cos (π) – πΏπ2(πβ²)2 sin(π)cos (π) = (π + π)πΏππβ²β²β πΏπ2πβ²β² cos2(π)
β(π + π)1/L( π1 πβ²) β (π + π)ππ β sin(π) + ππ₯π cos(π) + π2π₯β²cos (π) – πΏπ2(πβ²)2 sin(π)cos (π) / (π + π)πΏπβ πΏπ2cos2(π) = πβ²β²
β(π + π)1/L( π1 πβ²) β (π + π)ππ β sin(π) + ππ₯π cos(π) + π2π₯β²cos (π) – πΏπ2(πβ²)2 sin(π)cos (π) / (π + π)πΏπβ πΏπ2(1-sin2(π)) = πβ²β²
β(1 + π/m)1/L( π1 πβ²) β (π + π)π β sin(π) + ππ₯ cos(π) + π2π₯β²cos (π) – πΏπ(πβ²)2 sin(π)cos (π) / L(M+msin2(π)) = πβ²β²
β (π + π)πβ sin(π) – πΏπ(πβ²)2 sin(π)cos (π β (1 + π/m)1/L( π1 πβ²) + cos(π)β[ππ₯ + π2π₯β²] / L(M+msin2(π)) = πβ²β²
Now, we have two single variable-independent equations βvi)β and βvii)β
vi) π₯β²β² = [ πΏπ(πβ²)2 sin(π) + ππ β sin(π) cos(π) + 1/L[ π1 πβ² cos(π)] β ππ₯ β π2π₯β² ] / [π + m β sin2(π)]
vii) πβ²β² = β (π + π)πβ sin(π) – πΏπ(πβ²)2 sin(π)cos (π β (1 + π/m)1/L( π1 πβ²) + cos(π)β[ππ₯ + π2π₯β²] / L(M+msin2(π))
3.2 First order DE transformation
Now that we have two equations in terms of lower derivative variables, we can re-write them as two first order differential equations which is essential if we want to solve them numerically using π π’πππ πΎπ’π‘π‘π methods. Thus, we would need to re-write the variables as such:
π₯β² = π£
πβ² = π
π£β² = [ πΏππ2sin(π) + ππβsin(π)cos(π) + 1/L(π1πcos(π))βππ₯βπ2π£) ] / [ π + mβsin2(π) ]
π’ = [ β(π+π)πβsin(π) β πΏππ2sin(π)cos(π) β (1+π)(1/L)π1π + cos(π)[ππ₯ + π π£] ] / [πΏ(π + ππ ππ2(π))]
This method of re-writing is particularly useful when coding in python because we will be able to assign variables π₯, π, π£, π€, π£β², π€β², which are functions, to each component of the mechanical system; that is the cart and the pendulum.
4. Mechanical System in Python
Before we can model the system in python, we will import the necessary libraries which will allows us to use trigonometric functions, lines, etc.
import numpy as np # necessary libraries
import matplotlib.pyplot as plt
import scipy.integrate as integrate
import matplotlib.animation as animation
Similarly, we will need to choose certain parameters for our mechanical system. These will be the default parameters for all scenarios studied below.
M = 5 # Mass of the cart
m = 0.1 # mass of the pendulum
k = 25 # spring constant
L = 0.5 # lenght of string
g = 9.8 # gravitational acceleration
u1 = 0.1 # friction coefficient pendulum
u2 = 20 # friction coefficient cart
Then, we will need to assign the derivatives of our equations βπ£π)β and βπ£ππ)β certain states. Here, clearly:
πππ[0] = π₯β² π π‘ππ‘π [1] = π£ πππ[2] = πβ² π π‘ππ‘π[3] = π
As explained above, this is the way weβre writing our four equations in python.
def der_state(t, state): # Here, we are writing first order DE.
"""compute the derivative of the given state"""
der = np.zeros_like(state)
der[0] = state[1] # state[0] = x
der[2] = state[3] # state[2] = theta
der[1] = ((((L*m)*state[3]**2)*np.sin(state[2])) + m*g*np.sin(state[2])*np.cos(state[2]) + (u1/L)*state[3]*np.cos(state[2]) - k*state[0] - u2*state[1])/(M + m*np.sin(state[2])*np.sin(state[2]))
der[3] = (-(m + M)*g*np.sin(state[2]) - (L*m)*(state[3]**2)*np.sin(state[2])*np.cos(state[2]) - (1 + (M/m))*(u1/L)*state[3] + np.cos(state[2])*(k*state[0] + u2*state[1]))/(L*M + L*m*np.sin(state[2])*np.sin(state[2]))
return der
Similarly, we will need to choose an initial condition. Otherwise, neither the cart nor the pendulum will have motion. We will choose an initial condition on the cart and on the angle of the pendulum.
state0 = ([1, 0, 1, 0]) # [x],[x'],[theta],[theta'] initial conditions
The following code was used to solve the differential equations above. Then, the following set of code is used to define the cartesian coordinates so that we can plot on the graph.
sol = integrate.solve_ivp(der_state, (0, tf), state0, t_eval=T) #this solves both previous DE.
ang_pendulum_pos = sol.y[2]
x_quisite_position_cart = sol.y[0]
# Cartesian coordinates
x2 = x_quisite_position_cart
y2 = 0 # no motion in y direction.
x = x2 + L*np.sin(ang_pendulum_pos)
y = -L*np.cos(ang_pendulum_pos) #the y-axis points down
We will also import another library from matplotlib which will let us display the animation on our screen. We will set up an axis, provide limits, and the type of grid as follows:
from matplotlib import rc
rc('animation', html='html5')
fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2.1), ylim=(-1, 1)) # setting the graph axis
ax.grid()
Finally, we will define all our objects (cart, pendulum, lines, table, wall, spring), we will assign them colors, width, size, type of lines (using matplotlib libraries). All of these are explained in the full code provided. Thus, giving us something that looks like this:

4.1 Evaluating certain scenarios
Now, we have a working mechanical system in python.
https://colab.research.google.com/
Thus, we will start the evaluation of certain scenarios. In total we will study three main scenarios plus two interesting cases, these being:
- Over damped system
- Underdamped system
- Critically damped system
- System under Moonβs gravity
- System with heavy pendulum
Scenario #1
The system is overdamped. For this scenario, we will continue using the initial conditions and parameters of above, but we will only change the value of the cartβs friction coefficient βπ2β to 20 thereby giving it a significant opposing force.
Clearly our codeβs graphical representation of the system demonstrates that, with a high friction coefficient, the cart stops all motion in 1/4 of its period. The pendulum, however, can achieve some oscillation but immediately decays when the cart ultimately stops.
Scenario #2
The system is underdamped. Similarly, this scenario will continue using the initial conditions and parameters of above. However, this time we will change the value of the cartβs friction coefficient βπ2β to 0.1 thereby giving it a non-significant opposing force.
This time, the system will experience some simple harmonic behaviour. We see the cart and pendulum oscillate back and forth with almost no varying amplitude. This is anticipated since there is almost no resistance on neither of the components of the mechanical system.
Scenario #3
The system is critically damped. Likewise, this scenario will continue using the initial conditions and parameters of above. However, this time we will change the value of the cartβs friction coefficient βπ2β to 15 thereby giving it a significant but critical opposing force.
This is an interesting case because it demonstrates how the system returns to its equilibrium position faster than the overdamped scenario. With our chosen value of the cartβs friction coefficient, we see some overshooting thereby implying that this is a fraction of the actual of the critically damped value.
Scenario #4
The system under Moonβs gravity. This scenario will continue using the initial conditions and parameters of above. However, this time we will change the value of gravitational acceleration to one sixth of earths which corresponds to 1.62 π/s2 , the Moonβs surface gravity.
This is, particularly, an interesting case. It is possible to see the pendulum oscillate much more than it did with Earthβs gravity. Similarly, the cartβs motion is affected much more by the pendulum and thus its horizontal velocity is much faster.
Scenario #5
The system with heavy pendulum. This scenario will use the same initial conditions and parameters of above. However, this time only the mass of the pendulum βmβ will be changed to 4Kg instead of 0.1Kg.
Clearly, this is another simple harmonic oscillator case. The heavy pendulum, in combination with the low friction coefficients, results in a system that oscillates much faster than the previous cases. Similarly, this scenario possesses lots of momentum. Thus, resulting in a bigger amplitude. Lastly, the initial condition chosen plus the big mass of the pendulum, provide a significant initial conservative force which is immediately converted into kinetic energy thereby increasing the speed of oscillation.
5. Conclusion
Ultimately, this project has analyzed and modeled a pendulum-cart mechanism. B.R.I.T applied equations of motion and Newtonβs second law to derive four new equations. These four were mathematically manipulated leading to two known single-variable second order differential equations. Then, these two new equations were re-written as two first order differential equations allowing python, our program of choice, to solve them numerically thereby allowing us to represent the mechanical system graphically.
5.1. Resources
B.R.I.T made use of the following resources.
Neumann, E. (2021, June 25). Cart + Pendulum, retrieved from myPhysicsLβΊb.com
n/a (2002). Runge-Kutta Method, retrived from ScienceDirect.com
https://www.sciencedirect.com/
Hunter J. (2012). Matplotlib.axes.Axes.plot, retrieved from matplotlib.org
B.R.I.T would also like to thank professor Ivan T. Ivanov for its guidance and mentorship.