How to perform surface integral using an interpolation function?

23 views (last 30 days)
I have an interpolation function generated with "interp2":
G=@(x,y)interp2(xData,yData,zData,x,y);
when I try to integrate such function with "integral2" I either get some warning about failing to converge, or the computation time becomes extremely large. As an example:
A = integral2(G,xmin,xmax,ymin,ymax,'RelTol',1e-10,'AbsTol',1e-10,'method', 'auto');
Warning: Reached the maximum number of function evaluations (10000). The
result fails the global error test.
> In funfun\private\integral2Calc>integral2t at 130
In funfun\private\integral2Calc at 10
In integral2 at 106

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 May 2014
The main reason behind this behaviour is that you are trying ot use a general purpose integrator on a function which is not smooth enough to benefit from the high order integration methods used. The lack of smoothness between each piece forces the integrator to go to great expense. Because the newer integration functions (like "integral2") are much more conservative and reliable than the old ones, the expense may be great indeed.
The best (and by far more efficient) way to integrate over an interpolated function is to split between the various pieces, in fact the integral is extremely difficult to integrate at the borders of each piece , while the piece itself is very easy to integrate. You can then iterate through the pieces and add up all the contributions.
As an example:
A2 = 0;
for ix = 1:N-1
xleft = xData(ix);
xright = xData(ix+1);
for iy = 1:N-1
yleft = yData(iy);
yright = yData(iy+1);
A2 = A2 + integral2(G,xleft,xright,yleft,yright,'RelTol',1e-10,'AbsTol',1e-10,'method', 'auto');
end
end

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!