我想知道是否有办法计算积分而结果中没有出现错误?
ps = 50
rs = 5
#integral
def integrand(r,ps,rs):
return (ps)/((r/rs)*((1+(r/rs))**2))*4*3.14159265358979323*(r**2)
integrals = []
for i in r:
integrals.append(quad(integrand, 0 ,i,args=(ps,rs)))
当我这样做时,我为数组的每个元素得到一个元组(answer, error)
。
[(38.556383472098844, 4.280618467700097e-13), (237.6299245273545,
2.6382221355020717e-12), (441.6458592544819, 4.903254016746871e-12),
(697.2739237795256, 7.741295646507558e-12), (1018.8236494740419,
1.131121473678711e-11), (1363.0110665120408, 1.5132462688605584e-11),
(1742.8389896517806, 1.9349399745258517e-11), (2398.270086166211,
2.6626146689314857e-11), (3329.3070694046414, 3.696273364500337e-11)]
我对错误毫无兴趣;更重要的是,我需要一个充满数字的数组,而不是元组。
答案 0 :(得分:0)
是的,您只能追加积分方法返回的元组的第一个元素:
integrals.append(quad(integrand, 0 , i, args=(ps, rs))[0])
错误不会包含在您的结果中