How does the QUAD function handle improper integrals in MATLAB 7.14 (R2012a)?

조회 수: 6 (최근 30일)
I use the QUAD function to perform integration and would like to know how MATLAB handles improper integrals.
An improper integral is one in which the function cannot be evaluated at one of the end points.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2012년 7월 18일
The following code snippet creates an example:
>> myfun = @(x) 3*exp(x)./sqrt(1-x.^2);
>> quad(myfun,0,1)
ans =
9.3132
The function value at the end points are
>> myfun(0)
ans =
3
>> myfun(1)
ans =
Inf
Before beginning the integration, MATLAB checks the end points for infinities. If found, the offending point is purturbed slightly so that it moves away from the singularity.
You can see this by looking at the code for QUAD:
>> edit quad
The code snippet below from QUAD shows how this is done:
% Fudge endpoints to avoid infinities.
if ~isfinite(y(1))
y(1) = f(a+eps(superiorfloat(a,b))*(b-a),varargin{:});
fcnt = fcnt+1;
end
if ~isfinite(y(7))
y(7) = f(b-eps(superiorfloat(a,b))*(b-a),varargin{:});
fcnt = fcnt+1;
end
In the above code snippet, y(1) and y(7) are the interval end points.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품


릴리스

R2012a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by