下面是一个阻尼振动的例子
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
def pfun(y,x,beta,w):
w2=w*w
x,dot_x=y
ddot_x=-2*beta*dot_x-w2*x
return np.array([dot_x,ddot_x],dtype=float)
t=np.arange(0,6,0.01)
fun=odeint(pfun,[1,0],t,args=(1,10))
x=fun[:,0]
dot_x=fun[:,1]
plt.plot(t,x)
fun_x=interp1d(t, x, kind="cubic")
print(fun_x(3))
Smilie Vote is loading.