# 增加求解常微分方程的函数 odeint

from mipylib.numeric.integrate import odeintdef pend(y, t, b, c):    theta, omega = y    dydt = [omega, -b*omega - c*np.sin(theta)]    return dydtb = 0.25c = 5.0y0 = [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 integratedef 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/dtt = 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')

https://blog.sciencenet.cn/blog-611158-1376037.html

## 全部精选博文导读

GMT+8, 2024-8-12 09:45