Linear extrapolation with scatteredInterpolant

조회 수: 11 (최근 30일)
Maartencb
Maartencb 2016년 2월 18일
댓글: John D'Errico 2016년 2월 22일
Hi all,
I'm trying to linearly extrapolate a 2D interpolant made with scatteredInterpolant(). According to the documentation one can specify the extrapolation method in the function call, but I always get non-linear interpolation. Below an example, including the code to produce it. I'm trying to derive the zero level contour of the mound, but due to the non-linear extrapolation in some places the surface curves up and does not reach zero.
Is this a bug, or am I doing something wrong?
Thanks in advance, Maarten
X = [0.4980 0.4020 0.3050 0.2190 0.1180 0.2360 0.2390 0.2320 0.2280 0.2070 0.2730 0.1790 0.2320 0.1730 0.1790 0.1770]';
Y = [0.4270 0.4450 0.3970 0.3540 0.2820 0.6620 0.6220 0.5860 0.5260 0.3700 0.3560 0.3170 0.2160 0.1470 0.0790 0]';
Z = [0 0.1034 0.1521 0.1550 -0.0264 -0.0000 0.0303 0.0436 0.0254 0.1069 0.1063 0.0077 0.0884 -0.0093 -0.0050 0 ]';
sdi = scatteredInterpolant(X,Y,Z,'linear','linear')
xVec = linspace(min(X),max(X),50);
yVec = linspace(min(Y),max(Y),50);
[xMesh,yMesh]=meshgrid(xVec,yVec);
zMesh = sdi(xMesh,yMesh);
surf(xMesh,yMesh,zMesh);
hold on
plot3(X,Y,Z,'or','MarkerFaceColor','r')
xlabel X; ylabel Y; zlabel Z

답변 (2개)

John D'Errico
John D'Errico 2016년 2월 18일
Linear interpolation is not extrapolation. In fact, it is actually a bit more difficult to extrapolate intelligently in multiple dimensions. Extrapolation in general is never a good thing, but extrapolation of a bumpy mess will give you highly unpredictable results.
Yes, you can use my gridfit tool (find it on the file exchange) to do this. I expect that you won't be terribly happy with the results if you try to extrapolate too far though.

Maartencb
Maartencb 2016년 2월 22일
편집: Maartencb 2016년 2월 22일
Hi John,
thanks for your reply. I did indeed try your gridfit tool, but it didn't work for me. In the end the solution was easy. I realized that extrapolation wasn't necessary because I only needed to know he the surface inside the convex hull. I simply used quad2d() and a wrapper function that returns zero outside the hull (instead of NaN).
Still, I wonder if there's a bug in scatteredInterpolant() since it clearly seems to perform non-linear extrapolation even when linear is specified.
Best, Maarten
  댓글 수: 1
John D'Errico
John D'Errico 2016년 2월 22일
Please don't add a answer when your goal is only to make a comment.
I have no idea why gridfit did not work for you. I think it did work, but you got an answer that you did not want. Since you did not completely explain your problem, I cannot help more.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by