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

6 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Jul 2012
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.

More Answers (0)

Products


Release

R2012a

Community Treasure Hunt

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

Start Hunting!