SciPy is a package in Python that provides functions that can be used for numerical and mathematical computation. The integrate
sub-package in SciPy implements general-purpose integration methods in Python. The scipy.integrate.fixed_quad
method in SciPy computes a definite integral using a simple Gaussian quadrature of the fixed order n.
scipy.integrate.fixed_quad(func, a, b, args=(), n=5)
func
: This is a Python function or method representing the function to be integrated using the Gaussian quadrature. The function should accept vector inputs. When integrating a vector-valued function, the returned array must have the shape (..., len(x))
.
a
: It is the lower limit of integration. It has the float
type.
b
: It is the upper limit of integration. It has the float
type.
args
: This is an optional parameter which is a sequence of extra arguments passed to func
.
n
: This is the Gaussian quadrature’s order. The default value is .
val
: This is the computed Gaussian quadrature approximation to the integral. It has the float
type.
none
: This is the statistically returned value of None
.
Let’s see how to compute the Gaussian quadrature approximation of order of the function using the scipy.integrate.fixed_quad
method over the fixed interval .
import numpy as npfrom scipy import integrateprint(integrate.fixed_quad(np.sin, 0.0, np.pi/4, n=5))
numpy
library and the integrate
sub-package from the scipy
library.np.sin
method in the NumPy library as our function to be integrated. We pass np.sin
as the function and 0
and np.pi/4
as integration limits. is the order of the quadrature integration to the scipy.integrate.fixed_quad
. We then print the result.