
- 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 - integrate.tplquad() Method
The SciPy integrate.tplquad() method is used to calculate the triple numerical integration. It means a method can accept three variable say(x, y, z) to work on. This type of integration uses in various field such as physics, engineering, and environmental science.
Syntax
Following is the syntax of the SciPy integrate.tplquad() method −
tplquad(func, a, b, gfun, hfun, qfun, rfun)
Parameters
This function accepts the following parameter −
- func: This parameter is used to work with integrals.
- a: The integer value is passed to this parameter(limit of integration in x).
- b: The integer value is passed to this parameter(limit of integration in x).
- gfun: This parameter represent the lower boundry curve of y.
- hfun: This parameter represent the upper boundary curve in y.
- qfun: The parameter represent the lower boundary surface in z which must be a function and accept two order in sequential manner(x, y).
- rfun: This parameter represent the upper boundry surface in z.
Return value
This method returns the float value as result.
Example 1
Following is basic representation of volume of a paraboloid z = 4-x2 - y2 and the xy is a plane using Scipy integrate.tplquad() method.
from scipy import integrate # define the customize function def integrand(z, y, x): return 1 # limits for x and y a, b = -2, 2 gfun = lambda x: -2 hfun = lambda x: 2 qfun = lambda x, y: 0 rfun = lambda x, y: 4 - x**2 - y**2 # operation on integration res, err = integrate.tplquad(integrand, a, b, gfun, hfun, qfun, rfun) # print the result print(f"Volume: {res}, Error: {err}")
Output
The above code produces the following output −
Volume: 21.333333333333336, Error: 2.7943958177832873e-13
Example 2
To obtain the mass of a density function, it uses three units for density say[p(x,y,z) = x2 + y2 + z2] over the unit cube of [0,1]*[0,1]*[0,1]. Thus, this returns the result in the forms of float values.
from scipy.integrate import tplquad # define the customize function def density(z, y, x): return x**2 + y**2 + z**2 # limits for x, y, z a, b = 0, 1 gfun = lambda x: 0 hfun = lambda x: 1 qfun = lambda x, y: 0 rfun = lambda x, y: 1 # operation on integration res, err = tplquad(density, a, b, gfun, hfun, qfun, rfun) # print the result print(f"Mass: {res}, Error: {err}")
Output
The above code produces the following output −
Mass: 1.0, Error: 2.5808878251226036e-14
Example 3
The program calculate the integral of f(x,y,z) = x+y+z over the spherical region of radius 1 centered at the origin.
from scipy.integrate import tplquad import numpy as np # define the customize function def integrand(z, y, x): return x + y + z # limits for x, y, z a, b = -1, 1 gfun = lambda x: -np.sqrt(1 - x**2) hfun = lambda x: np.sqrt(1 - x**2) qfun = lambda x, y: -np.sqrt(1 - x**2 - y**2) rfun = lambda x, y: np.sqrt(1 - x**2 - y**2) # operation on integration res, err = tplquad(integrand, a, b, gfun, hfun, qfun, rfun) # print the result print(f"Integral: {res}, Error: {err}")
Output
The above code produces the following output −
Integral: 0.0, Error: 7.692504411238588e-10