||
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')
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-30 13:39
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社