quadgk
Adaptive Gauss-Kronrod quadrature, including infinite limits and singular endpoints.
Category: Mathematics > Numerical Integration and Differential Equations
Syntax
q = quadgk(fun, a, b)
Integrates fun from a to b.
[q, errbnd] = quadgk(fun, a, b)
Also returns an estimate of the error.
q = quadgk(fun, a, b, Name, Value)
Sets options such as 'AbsTol', 'RelTol' and 'Waypoints'.
Description
Infinite limits are mapped to a finite interval, and endpoint singularities of the type 1/sqrt(x) are tamed by a change of variables, which makes the method robust. A contour can be defined in the complex plane through complex waypoints.
integral is built on the same algorithm and is generally preferred in new code.
Input arguments
fun- Handle accepting a vector
xand returning a vector. a, b- Limits, which may be infinite.
'Waypoints'- Interior points at which to split the interval, for integrands with kinks or discontinuities.
Output arguments
q- Approximate value of the integral.
errbnd- Estimated upper bound on the absolute error.
Example
An integrable singularity
q = quadgk(@(x) 1./sqrt(x), 0, 1)
quadgk(@(x) exp(-x.^2), -Inf, Inf)
Output
q = 2.0000
ans = 1.7725