我正在尝试使用计算两个积分scipy.integrate.quad.
但是,由于第一个参数为负的gamma函数未在 中定义,我必须从 中选择版本。运行以下代码后,scipy
mpmath
from scipy.integrate import *
from mpmath import *
low, up = 5.630e5, 1.167e12
alpha, threshold = 1.05 , 2.15e10
beta = 274
def g(x, beta, low, up):
return gamma(-2/3) * (gammainc(-2/3, beta*(x/low)**3) - gammainc(-2/3, beta*(x/up)**3))
def Integrand1(x, low, threshold, alpha):
return pow(x/threshold, alpha) * g
def Integrand2(x, up, threshold):
return g
Integral1 = quad(Integrand1, low, threshold, args=(low, up, threshold, alpha, beta))
Integral2 = quad(Integrand2, threshold, up, args=(low, up, threshold, beta))
print(Integral1)
print(Integral2)
这是我不知道如何处理并需要帮助的错误消息:
回溯(最后一次调用):文件“test.py”,第 19 行,在 Integral1 = quad(Integrand1, low, threshold, args=(low, up, threshold, alpha, beta)) 文件“/home/username/ anaconda3/lib/python3.6/site-packages/mpmath/calculus/quadrature.py”,第 748 行,四点 [0],prec,epsilon,m,详细)文件“/home/username/anaconda3/lib/ python3.6/site-packages/mpmath/calculus/quadrature.py",第 215 行,对于 i in xrange(len(points)-1) 的总和:TypeError:'float' 类型的对象没有 len()
我只能猜测原因可能是quad
函数与使用定义的积分不兼容mpmath.