Python数值分析--------受迫钟摆模拟

解释说明,下次一定补上

        Python数值分析--------受迫钟摆模拟_第1张图片

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")

你可能感兴趣的:(数值分析,python)