python-3.xnumpyscipynumerical-integrationcalculus

Make the integrate.quad function return only the analytical value


The integrate.quad function in scipy displays the analytical and absolute error of the integration. How do I make it output just the analytical portion?

The code below returns (21.333333333333332, 2.3684757858670003e-13). I just want 21.3333

from scipy import integrate
x2 = lambda x: x**2
integrate.quad(x2, 0, 4)



Solution

  • This way you can print only the 21.3333

    from scipy import integrate
    x2 = lambda x: x**2
    results = integrate.quad(x2, 0, 4)
    
    print(results[0])
    

    The output will be:

    21.333333333333336