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
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!