vpaintegral
Numerical integration using variable precision
Description
vpaintegral(___,
uses additional options specified by one or more Name,Value
)Name,Value
pair
arguments.
Examples
Numerically Integrate Symbolic Expression
Numerically integrate the symbolic expression
x^2
from 1
to 2
.
syms x vpaintegral(x^2, 1, 2)
ans = 2.33333
Numerically Integrate Symbolic Function
Numerically integrate the symbolic function y(x) = x2 from 1
to 2
.
syms y(x) y(x) = x^2; vpaintegral(y, 1, 2)
ans = 2.33333
High-Precision Numerical Integration
vpaintegral
uses variable-precision
arithmetic while the MATLAB®
integral
function uses
double-precision arithmetic. Using the default values of tolerance,
vpaintegral
can handle values that cause the MATLAB
integral
function to overflow or underflow.
Integrate besseli(5,25*u).*exp(-u*25)
by using both
integral
and vpaintegral
. The
integral
function returns NaN
and issues a
warning while vpaintegral
returns the correct result.
syms u x f = besseli(5,25*x).*exp(-x*25); fun = @(u)besseli(5,25*u).*exp(-u*25); usingIntegral = integral(fun, 0, 30) usingVpaintegral = vpaintegral(f, 0, 30)
Warning: Infinite or Not-a-Number value encountered. usingIntegral = NaN usingVpaintegral = 0.688424
Increase Precision Using Tolerances
The digits
function does not affect
vpaintegral
. Instead, increase the precision of
vpainteral
by decreasing the integration tolerances. Conversely,
increase the speed of numerical integration by increasing the tolerances. Control the
tolerance used by vpaintegral
by changing the relative tolerance
RelTol
and absolute tolerance AbsTol
, which
affect the integration through the condition
Numerically integrate besselj(0,x)
from 0
to
pi
, to 32 significant figures by setting
RelTol
to 10^(-32)
. Turn off
AbsTol
by setting it to 0
.
syms x vpaintegral(besselj(0,x), [0 pi], 'RelTol', 1e-32, 'AbsTol', 0)
ans = 1.3475263146739901712314731279612
Using lower tolerance values increases precision at the cost of speed.
Complex Path Integration Using Waypoints
Integrate 1/(2*z-1)
over the triangular path
from 0
to 1+1i
to 1-1i
back
to 0
by specifying waypoints.
syms z vpaintegral(1/(2*z-1), [0 0], 'Waypoints', [1+1i 1-1i])
ans = - 8.67362e-19 - 3.14159i
Reversing the direction of the integral, by changing the order of the waypoints and exchanging the limits, changes the sign of the result.
Multiple Integrals
Perform multiple integration by nesting calls to
vpaintegral
. Integrate
syms x y vpaintegral(vpaintegral(x*y, x, [1 3]), y, [-1 2])
ans = 6.0
The limits of integration can be symbolic expressions or functions. Integrate over
the triangular region 0 ≤ x ≤ 1 and |y| < x by specifying the limits of the integration over y
in terms of x
.
vpaintegral(vpaintegral(sin(x-y)/(x-y), y, [-x x]), x, [0 1])
ans = 0.89734
Input Arguments
Tips
Version History
Introduced in R2016b