q = integral(fun, a, b)
q = integral(fun, a, b, name, value)
| Parameter | Description |
|---|---|
| fun | Integrand: function handle. |
| a | Lower limit of integration: real scalar (finite or infinite) or finite complex scalar. |
| b | Upper limit of integration: real scalar (finite or infinite) or finite complex scalar. |
| name, value | One or more name/value pairs: 'RelativeTolerance', 'AbsoluteTolerance', 'ArrayValued', 'Vectorized', 'Waypoints'. |
| Parameter | Description |
|---|---|
| q | Value of the integral. |
q = integral(fun, a, b) numerically integrates the function fun from a to b using global adaptive Gauss-Kronrod quadrature.
By default fun is assumed to be vectorized: it must accept a vector of abscissae and return a vector of the same size.
The limits a and b may be infinite (-Inf and/or Inf); a change of variable maps the interval to a finite one.
If a, b or a waypoint is complex, integral computes the path integral along the straight lines joining a, the waypoints in the given order, and b. Complex limits and waypoints must be finite.
The following name/value pairs are supported:
RelativeTolerance (or RelTol): relative error tolerance (default 1e-6).
AbsoluteTolerance (or AbsTol): absolute error tolerance (default 1e-10).
integral attempts to satisfy abs(q - Q) <= max(AbsoluteTolerance, RelativeTolerance * abs(q)) where Q is the exact value.
ArrayValued: when true, fun returns an array and is evaluated at a scalar abscissa (default false).
Vectorized: when false, fun is written for scalar inputs: it accepts a scalar x and returns a scalar, and integral evaluates it point by point (default true, faster). Ignored when ArrayValued is true.
Waypoints: vector of finite real or complex points used in the initial mesh. With real limits and real waypoints, the interval is split at the waypoints lying inside it (their order does not matter): use them to mark discontinuities or local extrema of the integrand. Do not use waypoints to specify singularities; split the interval instead. Complex waypoints define a piecewise linear contour.
q = integral(@(x) x.^2, 0, 1)
q = integral(@(x) exp(-x.^2), 0, Inf)
q = integral(@(x) [1; 1] .* x, 0, 1, 'ArrayValued', true)
format long
q1 = integral(@log, 0, 1)
q2 = integral(@log, 0, 1, 'AbsoluteTolerance', 1e-12, 'RelativeTolerance', 0)
format short
fun = @(x) 2*x - x^2;
q = integral(fun, 0, 1, 'Vectorized', false)
fun = @(z) 1 ./ (2*z - 1);
q = integral(fun, 0, 0, 'Waypoints', [1+1i, 1-1i])
| Version | Description |
|---|---|
| 2.0.0 | initial version |
| 2.0.0 | 'Waypoints' option and complex limits (contour integration) added. |
| 2.0.0 | 'Vectorized' option added: integrate functions written for scalar inputs. |
| 2.0.0 | 'AbsoluteTolerance' and 'RelativeTolerance' names added ('AbsTol' and 'RelTol' still accepted). |