【发布时间】:2018-11-06 04:54:47
【问题描述】:
我刚刚开始使用 Python 进行科学绘图来绘制微分方程的数值解。我知道如何使用模块来求解和绘制单微分方程,但对微分方程系统一无所知。如何绘制以下耦合系统?
我的微分方程组是:
dw/dx=y 和dy/dx=-a-3*H*y 和dz/dx=-H*(1+z)
a = 0.1 和 H=sqrt((1+z)**3+w+u**2/(2*a))
我的代码是:
import numpy as N
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def model(w,y,z,x,H):
dwdx=y
dydx=-a-3*H*y
dzdx=-H*(1+z)
a=0.1
H=sqrt((1+z)**3+w+u**2/(2*a))
return [w,y,z,H]
z0=1100 #initial condition
w0=-2.26e-8
y0=-.38e-4
H0=36532.63
b=0
c=10000
x=N.arange(b,c,0.01)
y=odeint(model,y0,x) #f=Function name that returns derivative values at requested y and t values as dydt = f(y,t)
w=odeint(model,w0,x)
z=odeint(model,z0,x)
plt.plot(w,x)
plt.plot(y,x)
plt.plot(z,x)
plt.legend(loc='best')
plt.show()
【问题讨论】:
标签: python-3.x numpy matplotlib scipy differential-equations