integral
Numerical integral of a function of one variable.
Category: Mathematics > Numerical Integration and Differential Equations
Syntax
q = integral(fun, a, b)
Integrates fun from a to b with adaptive quadrature.
q = integral(fun, a, b, Name, Value)
Sets options such as 'AbsTol', 'RelTol', 'ArrayValued' or 'Waypoints'.
Description
The default method is a global adaptive Gauss-Kronrod rule, which subdivides the interval where the estimated error is largest until the tolerances are met. Infinite limits are handled by a change of variable.
The integrand must be vectorized: write x.^2, not x^2. This is the usual cause of an error when first using integral.
Input arguments
fun- Handle
y = fun(x)that accepts a vectorxand returns a vector of the same size. a, b- Limits. They may be
-InforInf. 'ArrayValued'- Set
trueiffunreturns an array for each scalarx. 'Waypoints'- Interior points where the integrand has kinks or discontinuities.
Output arguments
q- Approximate value of the integral.
Example
Finite and infinite ranges
integral(@(x) x.^2, 0, 1)
integral(@(x) exp(-x.^2), -Inf, Inf)
sqrt(pi)
Output
ans = 0.3333
ans = 1.7725
ans = 1.7725