Numerical integration using variable precision
collapse all in page
Syntax
vpaintegral(f,a,b)
vpaintegral(f,x,a,b)
vpaintegral(___,Name,Value)
Description
example
vpaintegral(f,a,b)
numerically approximates f
from a
to b
. The default variable x
in f
is found by symvar
.
vpaintegral(f,[a b])
is equal to vpaintegral(f,a,b)
.
example
vpaintegral(f,x,a,b)
performs numerical integration using the integration variable x
.
example
vpaintegral(___,Name,Value)
uses additional options specified by one or more Name,Value
pair arguments.
Examples
Numerically Integrate Symbolic Expression
Numerically integrate the symbolic expression x^2
from 1
to 2
.
syms xvpaintegral(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 xf = 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 = NaNusingVpaintegral =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 xvpaintegral(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 zvpaintegral(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 yvpaintegral(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
collapse all
f
— Expression or function to integrate
symbolic number | symbolic variable | symbolic vector | symbolic matrix | symbolic multidimensional array | symbolic function | symbolic expression
Expression or function to integrate, specified as a symbolic number, variable, vector, matrix, multidimensional array, function, or expression.
a,b
— Limits of integration
list of two numbers | list of two symbolic numbers | list of two symbolic variables | list of two symbolic functions | list of two symbolic expressions
Limits of integration, specified as a list of two numbers, symbolic numbers, symbolic variables, symbolic functions, or symbolic expressions.
x
— Integration variable
symbolic variable
Integration variable, specified as a symbolic variable. If x
is not specified, the integration variable is found by symvar
.
Name-Value Arguments
Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: 'RelTol',1e-20
RelTol
— Relative error tolerance
1e-6
(default) | positive real number
Relative error tolerance, specified as a positive real number. The default is 1e-6
. The RelTol
argument determines the accuracy of the integration only if , where Q is the calculated integral. In this case, vpaintegral
satisfies the condition , where I is the exact integral value. To use only RelTol
and turn off AbsTol, set AbsTol
to 0
.
Example: 1e-8
AbsTol
— Absolute error tolerance
1e-10
(default) | non-negative real number
Absolute error tolerance, specified as a non-negative real number. The default is 1e-10
. AbsTol
determines the accuracy of the integration if , where Q is the calculated integral. In this case, vpaintegral
satisfies the condition , where I is the exact integral value. To turn off AbsTol
and use only RelTol, set AbsTol
to 0
.
Example: 1e-12
Waypoints
— Integration path
vector of numbers | vector of symbolic numbers | vector of symbolic expressions | vector of symbolic functions
Integration path, specified as a vector of numbers, or as a vector of symbolic numbers, expressions, or functions. vpaintegral
integrates along the sequence of straight-line paths (lower limit to the first waypoint, from the first to the second waypoint, and so on) and finally from the last waypoint to the upper limit. For contour integrals, set equal lower and upper limits and define the contour using waypoints.
MaxFunctionCalls
— Maximum evaluations of input
10^5
(default) | positive integer | positive symbolic integer
Maximum evaluations of input, specified as a positive integer or a positive symbolic integer. The default value is 10^5
. If the number of evaluations of f is greater than MaxFunctionCalls
, then vpaintegral
throws an error. For unlimited evaluations, set MaxFunctionCalls
to Inf
.
Tips
Ensure that the input is integrable. If the input is not integrable, the output of
vpaintegral
is unpredictable.The
digits
function does not affectvpaintegral
. To increase precision, use the RelTol and AbsTol arguments instead.
Version History
Introduced in R2016b
See Also
diff | int | integral | vpa
Topics
- Integration
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office