在以下使用odeint
解决ODE的代码中,我遇到了这样的问题
od = odeint(OD_H, od0, [z1, z], args=(delt, omgm0, H0,))[-1]
File "C:\Python36-32\lib\site-packages\scipy\integrate\odepack.py", line 244, in odeint
int(bool(tfirst)))
TypeError: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'
代码是:
def OD_H(z, od, delt, omgm0, H0):
div1 = np.divide(1, (1 + z), where = (1 + z)!= 0)
a = (1 + z)**(-1)
M = 1
B = 3
Q = 2 * (2 - delt) * (B/(3 * M**2))**(1/(2*(delt-2))) * (H0 * (omgm0)**(0.5))**((1-delt)/(delt-2))
dMdt = -div1 * od * (1 - od) * (2 * delt - 1 + Q * (1 - od)**((1 - delt)/(2*(2-delt))) * od**(1/(2 *(2-delt))) * exp((3*(1-delt)*np.log(a))/(2*(2-delt))))
return dMdt
def ant(z, od0, delt, omgm0, H0):
z1 = 0
od = odeint(OD_H, od0, [z1, z], args=(delt, omgm0, H0,))[-1]
return od
for z in np.arange(0,3.1,0.1):
print(ant(z, 0.7, 1.1, 0.3, 67))
我不知道问题是什么。我发现的唯一一件事是关于复杂的值。感谢您对解决方案的帮助。