- 积分
- 55946
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
参考scipy的odeint函数,在MeteoInfo 3.5.5版本中增加了求解常微分方程的函数 odeint 。调用了Apache Commons Math库中的相关功能,并用Jython进行了封装。
求解受重力摩擦作用的摆锤角θ的二阶微分方程示例:
- from mipylib.numeric.integrate import odeint
- def pend(y, t, b, c):
- theta, omega = y
- dydt = [omega, -b*omega - c*np.sin(theta)]
- return dydt
- b = 0.25
- c = 5.0
- y0 = [np.pi - 0.1, 0.0]
- t = np.linspace(0, 10, 101)
- sol = odeint(pend, y0, t, args=(b, c))
- plot(t, sol[:, 0], 'b', label='theta(t)', linewidth=2)
- plot(t, sol[:, 1], 'g', label='omega(t)', linewidth=2)
- legend(loc='lower right')
- xlabel('t')
- grid()
Lorenz吸引子常微分方程组求解:
- from mipylib.numeric import integrate
- def lorenz(p,t,s,r,b):
- x,y,z = p
- return s*(y-x), x*(r-z)-y, x*y-b*z # dx/dt,dy/dt,dz/dt
- t = np.arange(0, 30, 0.01)
- track1 = integrate.odeint(lorenz, (0.0,1.00,0.0), t, args=(10.0,28.0,2.6))
- track2 = integrate.odeint(lorenz, (0.0,1.01,0.0), t, args=(10.0,28.0,2.6))
- axes3d()
- plot3(track1[:,0], track1[:,1], track1[:,2], linewidth=2, color='r')
- plot3(track2[:,0], track2[:,1], track2[:,2], linewidth=2, color='g')
|
|