In: Computer Science
Python Code :
import numpy as np
from scipy.integrate import odeint
import math
import matplotlib.pyplot as plt
#finding the differentiation
def differentiation(variables,time,a,b,c,d):
x = variables[0]
y = variables[1]
dx = y
dt = -(a/d)*y-c*math.sin(x)
dx_dt =[dx,dt]
return dx_dt
#input data
a=0.05
b=9.81
c=1
d=1
#initial condition
initial = [0,3]
#plot the time
time = np.linspace(0,20,240)
data = odeint(differentiation,initial,time,args =
(a,b,c,d))
#creating the
name=1
for i in range(0,240):
name_of_file = str(name)+'.png'
name= name+1
plt.figure()
plt.plot([10,c*math.sin(data[i,0])+10],[10,10-c*math.cos(data[i,
0])],marker="o")
plt.xlim([0,20])
plt.ylim([0,20])
plt.savefig(name_of_file)
plt.plot(time,data[:,0],'b-')
plt.plot(time,data[:,1],'r--')
plt.show()
You will 240 images as output.Few are given below.FInal output will be in final image ie.., 240.png
output 1 :
output 2 :
output 3 :
Output 4 :
Output5 :
Final ouput :