Numerical integration using variable precision
数值整合符号表达式x^2
从1
to2
。
Syms x Vpaintegral(x ^ 2,1,2)
ans = 2.33333
Numerically integrate the symbolic functiony(x) =x2从1
to2
。
ysms y(x)y(x)= x ^ 2;vpaintegral(y,1,2)
ans = 2.33333
vpaintegral
使用MATLAB时使用可变精度算术®㈡egral
function uses double-precision arithmetic. Using the default values of tolerance,vpaintegral
can handle values that cause the MATLAB㈡egral
function to overflow or underflow.
整合besseli(5,25*u).*exp(-u*25)
by using both㈡egral
和vpaintegral
。这㈡egral
function returnsNaN
并在此时发出警告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)
警告:遇到无限或不值的值。使用隔膜= NaN使用vppaintegral = 0.688424
这digits
功能不会影响vpaintegral
。Instead, increase the precision ofvpainter
by decreasing the integration tolerances. Conversely, increase the speed of numerical integration by increasing the tolerances. Control the tolerance used byvpaintegral
by changing the relative toleranceRELTOL.
和绝对的宽容AbsTol
, which affect the integration through the condition
Numerically integrateBesselj(0,x)
从0
toPI.
,通过设置到32个重要的数字RELTOL.
to10^(-32)
。Turn offAbsTol
by setting it to0
。
Syms X vpaintegral(贝塞尔夫(0,x),[0 pi],'Reltol',1e-32,'Abstol',0)
ans = 1.3475263146739901712314731279612
Using lower tolerance values increases precision at the cost of speed.
整合1 /(2 * Z-1)
over the triangular path from0
to1 + 1i
to1-1i
back to0
by specifying waypoints.
syms z vpaintegral(1 /(2 * z-1),[0 0],'waypoints',[1 + 1i 1-1i])
ANS = - 8.67362E-19 - 3.14159i
通过更改航路点的顺序并交换限制,改变结果的顺序来逆转积分的方向。
Perform multiple integration by nesting calls tovpaintegral
。整合
syms x y vpaintegral(vpaintegral(x*y, x, [1 3]), y, [-1 2])
ans = 6.0
这limits of integration can be symbolic expressions or functions. Integrate over the triangular region0 ≤x≤1.和|y| < xby specifying the limits of the integration overy
in terms ofx
。
vpaintegral(vpaintegral(sin(x-y)/(x-y), y, [-x x]), x, [0 1])
ANS = 0.89734.