解释说明,下次一定补上
import matplotlib.pyplot as plt
from math import *
rangee = 1000
h = 0.001
step = int(rangee/h)
q = 0.5
w = 2/3
b = 1.15
fun = lambda x1,x2,t:-sin(x1)-q*x2+b*cos(w*t)
x1 = [0] + [0 for i in range(step)]
x2 = [1] + [0 for i in range(step)]
t = [0] + [0 for i in range(step)]
for i in range(step):
x1[i+1] = x1[i] + h * x2[i]
x2[i+1] = x2[i] + h * fun(x1[i],x2[i],t[i])
t[i+1] = t[i] + h
plt.plot(t,x1)
plt.plot(t,x2)
plt.savefig("pendulum.jpg")