scipy.integrate解ode的例子

下面是一个阻尼振动的例子

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.
✿ 阅读数:1,046  分类:文章

发表评论

邮箱地址不会被公开。 必填项已用*标注

Captcha Code