###前提・実現したいこと
積分を含むある関数を定義して、使おうとしているのですが、具体的な値を代入するとうまくいきません。
最終的にやりたいことは、以下の関数m_model_00(x)のグラフをxy平面上に書くことです。
###発生している問題・エラーメッセージ
quadpack.error: Supplied function does not return a valid float.
###該当のソースコード
python
import math
import numpy as np
import scipy.optimize
from scipy import integrate
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
import scipy
def dL(z,omega_m,omega_l,H0,c):
def integrand(x):
return 1. / np.sqrt((1.+x)*2.(1.+xomega_m)-x(2.+x)*omega_l)
if omega_m + omega_l ==1: i=integrate.quad(integrand,0.,z) return c*(1.+z)/H0*i[0] elif omega_m + omega_l > 1: i=integrate.quad(integrand,0.,z) return c*(1.+z)/(H0*np.sqrt(abs(1.-omega_m-omega_l)))*np.sin(np.sqrt(abs(1.-omega_m-omega_l))*i[0]) else: i=integrate.quad(integrand,0.,z) return c*(1.+z)/(H0*np.sqrt(abs(1.-omega_m-omega_l)))*np.sinh(np.sqrt(abs(1.-omega_m-omega_l))*i[0])
dL = numpy.vectorize(dL, excluded=("omega_m","omega_l","H0","c"))
def m_model(z,omega_m,omega_l,H0,MB,):
return MB + 5.0*np.log(dL(z,omega_m,omega_l,H0,1.))+25.0
def m_model_00(x):
return m_model(x,0.,0.,0.7,-1.8,1.)
以下、ターミナルで実行した結果です。
execfile("problem_set_04_1b.py")
m_model_00(0.4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "problem_set_04_1b.py", line 44, in m_model_00
return m_model(x,0.,0.,0.7,-1.8)
File "problem_set_04_1b.py", line 31, in m_model
return MB + 5.0np.log(dL(z,omega_m,omega_l,H0))+25.0
File "problem_set_04_1b.py", line 26, in dL
return c(1.+z)/(H0*np.sqrt(abs(1.-omega_m-omega_l)))*np.sinh(np.sqrt(abs(1.-omega_m-omega_l))*integrate.quad(integrand,0.,z))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/integrate/quadpack.py", line 252, in quad
retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/integrate/quadpack.py", line 317, in _quad
return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
quadpack.error: Supplied function does not return a valid float.
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報