<jupyter_start><jupyter_text>Simple pendulum  We consider here the simple pendulum system, with no frictions and with arbitrary inital conditions on the angle at time $t=0$. However, we impose a zero intial velocity. As generalized coordinate we choose the angle between the vertical and the rope. The Lagrangian of the system reads  and the corresponding equation of motion, from which we generated the data $\theta(t)$ is<jupyter_code>import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>We want to use ode, that means we have to reduce the second order deifferential eqation into two first order differential equations$$\ddot{\theta} = -(g/\ell) \sin\theta $$Let $z = \dot{\theta}$ and then we get$$ \dot{z} =  -(g/\ell) \sin\theta $$<jupyter_code>def simple_pend(theta,t,g,l,m):
    theta1=theta[0]
    theta2=theta[1]
    # first differential equation
    dtheta1dt=theta2
    # second differential equation
    dtheta2dt=-g/l*np.sin(theta1)
    dthetadt=[dtheta1dt,dtheta2dt]
    return dthetadt<jupyter_output><empty_output><jupyter_text>set initial conditions for the rate of change of the angle $\dot{\theta}$ and the angle $\theta$, values of the lenght of the pendulum and mass. We set the time one-dimensional grid<jupyter_code>Pi=3.1415926;
g=1;
l=1;
m=1;
theta_0=[Pi/6,0];
t = np.linspace(0,20,400)
theta=odeint(simple_pend,theta_0,t,args=(g,l,m))
plt.plot(t,theta[:,0],'r--')
#plt.plot(t,theta[:,1],'b-')
plt.xlabel('time')
plt.ylabel('theta(t)')
fig, ax = plt.subplots()

ax.plot(theta[:,0], theta[:, 1])
ax.set_aspect(1)<jupyter_output><empty_output><jupyter_text>Display the content of theta as a vector [$\theta, \dot{\theta}$]<jupyter_code>theta<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup