(Not recommended) Vectorized quadrature
quadv is not recommended. Use
integral with the
Q = quadv(fun,a,b)
Q = quadv(fun,a,b,tol)
Q = quadv(fun,a,b,tol,trace)
[Q,fcnt] = quadv(...)
Q = quadv(fun,a,b) approximates the integral of the complex
b to within an error of
1.e-6 using recursive
adaptive Simpson quadrature.
fun is a function handle. The function
Y = fun(x) should accept a scalar argument
x and return an array result
components are the integrands evaluated at
b must be finite.
Parameterizing Functions explains how to
provide addition parameters to the function
fun, if necessary.
Q = quadv(fun,a,b,tol) uses the absolute error tolerance
tol for all the integrals instead of the default, which is
The same tolerance is used for all components, so the results obtained with
quadv are usually not the same as those obtained with
quad on the individual components.
Q = quadv(fun,a,b,tol,trace) with non-zero
trace shows the values of
[fcnt a b-a
Q(1)] during the recursion.
[Q,fcnt] = quadv(...) returns the number of function
The list below contains information to help you determine which quadrature function in MATLAB® to use:
quad function might be most efficient for low
accuracies with nonsmooth integrands.
quadl function might be more efficient than
quad at higher accuracies with smooth
quadgk function might be most efficient for high
accuracies and oscillatory integrands. It supports infinite intervals and can
handle moderate singularities at the endpoints. It also supports contour
integration along piecewise linear paths.
quadv function vectorizes
for an array-valued
If the interval is infinite, , then for the integral of
fun(x) to exist,
fun(x) must decay as
quadgk requires it to decay rapidly. Special
methods should be used for oscillatory functions on infinite intervals, but
quadgk can be used if
quadgk function will integrate functions that are
singular at finite endpoints if the singularities are not too strong. For
example, it will integrate functions that behave at an endpoint
>= -1/2. If the function is singular at points inside
(a,b), write the integral as a sum of integrals over
subintervals with the singular points as endpoints, compute them with
quadgk, and add the results.
For the parameterized array-valued function
function Y = myarrayfun(x,n) Y = 1./((1:n)+x);
the following command integrates
myarrayfun, for the parameter
value n = 10 between a = 0 and b = 1:
Qv = quadv(@(x)myarrayfun(x,10),0,1);
The resulting array
Qv has 10 elements estimating
k = 1:10.
The entries in
Qv are slightly different than if you compute the
quad in a loop:
for k = 1:10 Qs(k) = quadv(@(x)myscalarfun(x,k),0,1); end
function y = myscalarfun(x,k) y = 1./(k+x);