Linear dynamical system
The equation of motion for the pendulum is found by equating the mass times acceleration of the pendulum bob to the component of the force acting on the bob – its weight – along the direction of motion. The bob moves on the arc of a circle of radius , and the distance traveled along the tangent to the arc is denoted, is the length of the pendulum.
Question
1 - Set the governing equation
2 - Write a program to solve the obtained differential equation.
3 - Plot the time evolution of the angle and represent the corresponding phase space.
Solution
1
"""
2
@author: yacine.mezemate
3
"""
4
import numpy as np
5
from math import *
6
from scipy.integrate import odeint
7
import matplotlib.pyplot as plt
8
9
g = 9.81
10
L = 1
11
theta0 = (10*2*pi)/360
12
omega0 = 5*2*pi/360
13
14
x0 = np.array([theta0, omega0])
15
t = np.linspace(0,pi*2,100)
16
17
global k, damping_force
18
damping_force = 0
19
k = g*L
20
21
def SystemEquation((x1,x2), t0):
22
23
return [x2, -k*sin(x1) -damping_force*x1]
24
25
26
27
x_t = odeint(SystemEquation, x0, t)
28
29
plt.figure(1)
30
plt.plot(t,x_t[:,0])
31
plt.ylabel(r"$\theta$", fontsize=18)
32
plt.xlabel(r"time", fontsize=18)
33
plt.show()
34
35
plt.figure(2)
36
plt.plot(x_t[:,1], x_t[:,0])
37
plt.ylabel(r"$\dot{\theta}$", fontsize=18)
38
plt.xlabel(r"$\theta$", fontsize=18)
39
plt.show()
40