Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

# What is the scipy.integrate.quadrature() method in Python? Abdul Monum

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

### Overview

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 f(x) is approximated by fitting the straight line through the weighted sum of function values at x0 and x1

### Syntax

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)
The syntax of the scipy.integrate.quadrature() function

### Parameters

• 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 tol or the relative change is less than rtol. Its default value is 1.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.

### Return value

• 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.

### Code

from scipy import integrateimport numpy as npprint(integrate.quadrature(np.sin, 0.0, np.pi/4))
Using the integrate.quadrature() function

### Explanation

• 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 $0$ to $\pi/4$.

RELATED TAGS

python
communitycreator

CONTRIBUTOR Abdul Monum

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 