# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# quadv

Vectorized quadrature

`quadv` will be removed in a future release. Use `integral` with the `'ArrayValued'` option instead.

## Syntax

`Q = quadv(fun,a,b)Q = quadv(fun,a,b,tol)Q = quadv(fun,a,b,tol,trace)[Q,fcnt] = quadv(...)`

## Description

`Q = quadv(fun,a,b)` approximates the integral of the complex array-valued function `fun` from `a` to `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 `Y`, whose components are the integrands evaluated at `x`. Limits `a` and `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 `1.e-6`.

 Note   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 evaluations.

The list below contains information to help you determine which quadrature function in MATLAB® to use:

• The `quad` function might be most efficient for low accuracies with nonsmooth integrands.

• The `quadl` function might be more efficient than `quad` at higher accuracies with smooth integrands.

• The `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.

• The `quadv` function vectorizes `quad` for an array-valued `fun`.

• If the interval is infinite, $\left[a,\infty \right)$, then for the integral of `fun(x)` to exist, `fun(x)` must decay as `x` approaches infinity, and `quadgk` requires it to decay rapidly. Special methods should be used for oscillatory functions on infinite intervals, but `quadgk` can be used if `fun(x)` decays fast enough.

• The `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 `c` like `log|x-c|` or `|x-c|p` for ```p >= -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.

## Examples

For the parameterized array-valued function `myarrayfun`, defined by

```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 ```Q(k) = log((k+1)./(k))```, for `k = 1:10`.

The entries in `Qv` are slightly different than if you compute the integrals using `quad` in a loop:

```for k = 1:10 Qs(k) = quadv(@(x)myscalarfun(x,k),0,1); end```

where `myscalarfun` is:

```function y = myscalarfun(x,k) y = 1./(k+x);```

## See Also

#### Introduced before R2006a

Was this topic helpful?

Watch now