In [1]:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
In [10]:
g=9.81
l=2.85
b=0.0 #With friction
def dTheta_dt(Theta, t):
    return [Theta[1], -b*Theta[1] -g/l*np.sin(Theta[0])]
Theta0 = [np.pi/10, 0]
t = np.linspace(0, 5, 200)
ThetaSolution = odeint(dTheta_dt, [np.pi/10, 0], t)
ThetaDraw = ThetaSolution[:,0]
T=2*np.pi*np.sqrt(l/g);print("T=%2.2f s"%T)
T=3.39 s
In [11]:
plt.xlabel("t [s]")
plt.ylabel("Theta [rad]")
plt.title("Pendulum simulation")
plt.plot(t,ThetaDraw);
In [ ]: