
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
Scipy - Single Integration (quad)
Single Integration in SciPy
SciPy's Single Integration can be done with the help of quad() function which is a powerful tool used for one-dimensional numerical integration i.e. definite integrals. It is part of the scipy.integrate module and is based on adaptive quadrature methods.
This function computes the integral of a given function over a specified range by returning both the integral's result and an estimate of the error. It is especially useful for smooth functions over finite limits and handles both simple and complex integrands.
The quad() function is widely used in scientific computing for tasks involving the integration of continuous functions. Mathematically the quad() function evaluates definite integrals of the form as follows −

Syntax
Following is the syntax of the scipy.integrate.quad() function which is used to calculate the Single Integration −
scipy.integrate.quad(func, a, b, args=(), full_output=0, epsabs=1.49e-08, epsrel=1.49e-08, limit=50, points=None, weight=None, wvar=None, wopts=None, maxp1=50, limlst=50, complex_func=False)
Parameters
Here are the parameters of the scipy.integrate.quad() function −
- func: The function to integrate. It should accept a single argument and return a scalar.
- a: The lower limit of integration (float).
- b: The upper limit of integration (float).
- args(Optional): A tuple of additional arguments to pass to the function.
- full_output(Optional): If the value is set to 1 then the output includes error estimates and additional information.
- epsabs(Optional): Absolute error tolerance. Default value is 1.49e-08.
- epsrel(Optional): Relative error tolerance. Default value is 1.49e-08.
- limit(Optional): The maximum number of subdivisions. Default value is 50.
- points(Optional): A list of points at which to evaluate the integrand.
- weight(Optional): A string specifying the type of weight function ('cauchy', 'cosine', 'chebyshev', etc.).
- wvar(Optional): A variable for the weight function.
- wopts(Optional): Options for the weight function.
- maxp1(Optional): Maximum number of poles for the weight function. Default value is 50.
- limlst(Optional): Maximum number of limit points. Default value is 50.
- complex_func(Optional): If the value is set to True then it indicates that the function is complex.
Example of Single Integration
Following is the example of finding the Single Integration of the function f(x) = sin(x) over the interval [o,] then the result will be 2 −
import numpy as np from scipy import integrate # Define the function to be integrated def f(x): return np.sin(x) # Perform the integration from 0 to p result, error = integrate.quad(f, 0, np.pi) # Display the results print(f"Integral Result: {result}")
Below is the output of the Single Integration of the given function −
Integral Result: 2.0
Handling Infinite Limits
In scipy.integrate.quad() function, we can handle infinite limits for improper integrals by passing np.inf or -np.inf as the limits of integration.
Example
Here in this example the function e-x is integrated from 0 to infinity which converges to 1. The quad() function is capable of handling such improper integrals will automatically applying appropriate techniques to compute them.
from scipy import integrate import numpy as np # Define the function to integrate def f(x): return np.exp(-x) # Perform the integration with an infinite upper limit result, error = integrate.quad(f, 0, np.inf) print("Integral Result:", result) # Output: 1.0 print("Estimated Error:", error) # Output: Estimated error in the result
Here is the output of handling the infinite limits in single Integration in scipy −
Integral Result: 1.0000000000000002 Estimated Error: 5.842606701570796e-11
Error Tolerances
In scipy.integrate.quad() the error tolerances are controlled by two optional parameters namely, epsabs and epsrel. These parameters define the absolute and relative error tolerance by ensuring the result's precision.
- epsabs: Absolute error tolerance. The algorithm stops when the absolute error estimate is below this value. Default value is 1.49e-08.
- epsrel: Relative error tolerance. The algorithm stops when the relative error estimate is below this value. Default value is 1.49e-08.
The integration stops when the absolute error is less than epsabs or when the relative error is less than epsrel. We can adjust these values to increase precision or speed up computation.
Example
In this example we set both epsabs and epsrel to 1e-6 which means the integration will continue until the error estimate is smaller than these tolerances −
from scipy import integrate import numpy as np # Define the function to integrate def f(x): return np.exp(-x) # Perform the integration with an infinite upper limit result, error = integrate.quad(f, 0, np.inf) print("Integral Result:", result) # Output: 1.0 print("Estimated Error:", error) # Output: Estimated error in the result
Below is the output of the Error Tolerance of single integration −
Integral Result: 2.0 Estimated Error: 2.220446049250313e-14
Complex Functions
In scipy.integrate.quad() we can integrate complex-valued functions by setting the complex_func parameter to True. This allows quad() function to handle functions that return complex numbers. The integration is performed separately for the real and imaginary parts of the function.
Example
In this example we will integrate eix from 0 to by demonstrating how to handle complex-valued integrals using SciPy's quad() function.
from scipy import integrate import numpy as np # Define a complex function def complex_function(x): return np.exp(1j * x) # e^(ix) # Perform the integration from 0 to p with complex function handling result, error = integrate.quad(complex_function, 0, np.pi, limit=100, complex_func=True) print("Integral Result:", result) print("Estimated Error:", error)
Here is the output of the Complex functions single integration in scipy −
Integral Result: (3.6775933888827275e-17+2j) Estimated Error: (2.2102239425853306e-14+2.220446049250313e-14j)
Finally we can conclude the SciPys quad() function is highly versatile, capable of efficiently handling smooth functions, improper integrals, complex-valued functions and even providing detailed diagnostics. Its ideal for situations where analytic solutions to integrals are difficult or impossible to obtain by making it a fundamental tool in numerical computation.