The scipy.integrate.quadrature() method in Python computes a definite integral using the numerical integration method of the fixed-tolerance Gaussian quadrature. The method takes a Python function, limits of integration, and absolute tolerance value as arguments and calculates the definite integral using the Gaussian quadrature.
The function prototype is as follows:
scipy.integrate.quadrature(func, a, b, args = (),tol = 1.49e-08,rtol = 1.49e-08,maxiter = 50,vec_func = True,miniter = 1)
func: This is the Python function or the method that is being integrated.
a: This is a float value that specifies the lower limit of integration.
args: This is an optional tuple parameter. It specifies the extra arguments to be passed to the func function.
tol, rtol: This is an optional float value that defines the absolute tolerance.
Note: Iteration stops when the error between the last two iterates is less than
tolor the relative change is less thanrtol. Its default value is1.49e-08.
maxiter: This is an optional int value that specifies the maximum order of the Gaussian quadrature.
miniter: This is an optional int value that specifies the minimum order of the Gaussian quadrature.
vec_func: This is an optional bool value that specifies True or False, if func handles arrays as arguments. The default value is True.
val: This float value computes the Gaussian quadrature approximation to the integral within the absolute tolerance.
err: This float value tells the difference between the last two estimates of the integral.
from scipy import integrateimport numpy as npprint(integrate.quadrature(np.sin, 0.0, np.pi/4))
Line 1ā2: We import the required libraries.
Line 4: We use the sine function, np.sin, from the NumPy library and pass it to the integrate.quadrature method. The method integrates it using the Gaussian quadrature method with integration limits from to .