[Tutor] err in integration

Peter Otten __peter__ at web.de
Sat May 1 13:04:28 EDT 2021


On 01/05/2021 09:19, Msd De wrote:

> I tried this :
> print("The numerical result is {J1} (+-{err})".format(J1=J1, err=err))
> o/p is :
> The numerical result is 0.203920669888 (+-None)
> I would like it print number in place of +-None
> Thanks

According to the docs

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.fixed_quad.html

"""
scipy.integrate.fixed_quad(func, a, b, args=(), n=5)
Compute a definite integral using fixed-order Gaussian quadrature.

[...]

Returns
val float
Gaussian quadrature approximation to the integral

none None
Statically returned value of None
"""

the algorithm you chose does not provide an error margin.
You might consider an alternative that does, like:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quadrature.html#scipy.integrate.quadrature

"""
scipy.integrate.quadrature(func, a, b, args=(), tol=1.49e-08, 
rtol=1.49e-08, maxiter=50, vec_func=True, miniter=1)[source]
Compute a definite integral using fixed-tolerance Gaussian quadrature.

[...]

Returns
val float
Gaussian quadrature approximation (within tolerance) to integral.

err float
Difference between last two estimates of the integral.
"""



More information about the Tutor mailing list