quad

Numerical integral by adaptive Simpson quadrature (older interface).

Category: Mathematics > Numerical Integration and Differential Equations

Syntax

q = quad(fun, a, b)

Integrates fun from a to b.

q = quad(fun, a, b, tol)

Uses the absolute tolerance tol.

Description

quad bisects the interval recursively and applies Simpson's rule until the estimated error is below the tolerance. It is kept for old code; integral is more accurate and more general (it accepts infinite limits and options).

Write the integrand with element-wise operators.

Input arguments

fun
Handle that accepts a vector x and returns a vector.
a, b
Finite limits.
tol
Absolute tolerance. Default 1e-6.

Output arguments

q
Approximate value of the integral.

Example

Integral of x^2 from 0 to 1

quad(@(x) x.^2, 0, 1)
Output
ans = 0.3333

See also

integral quadl quadgk trapz