.quad()
Anonymous contributor
Published Jan 30, 2025
Contribute to Docs
The .quad()
function in SciPy calculates the definite integral of a given function over a specified interval [a, b]
. It is part of the scipy.integrate
module and provides both the integral value and an estimate of the absolute error. The function is useful for numerical integration, especially when dealing with complicated functions or when an analytical solution is difficult to obtain.
Syntax
integrate.quad(func, a, b, args=(), full_output=0, complex_func=False, ...)
func
: The function to integrate.a
: The lower limit to use for integration.b
: The upper limit to use for integration.args
(Optional): A tuple of additional arguments to pass tofunc
. Default is an empty tuple()
.full_output
(Optional): If non-zero, it returns additional information (such as the error estimate and evaluation statistics).complex_func
(Optional): IfTrue
, the function is assumed to return complex values. Default isFalse
.
Note: The ellipsis (
...
) indicates that there can be additional optional parameters beyond those listed here.
Example
The following example demonstrates the usage of the .quad()
function to calculate the definite integral of $x^3$ from 1 to 3:
from scipy import integrate# Define a functionfunc = lambda x: x**3# Calculate the definite integral of the function from 1 to 3res = integrate.quad(func, 1, 3)# Print the resultprint(res)
The above code produces the following output:
(20.0, 2.220446049250313e-13)
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SciPy on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours