bilinear extrapolation based on interp2
이전 댓글 표시
[X,Y] = meshgrid(0:10);
Z = X.^2 + Y.^2;
[Xq,Yq] = meshgrid(0:0.25,10);
V = interp2(X,Y,Z,Xq,Vq,'linear');
I want to use interp2 to (bi)linearly interpolate the function Z(x,y) in the interior of the grid.
Although I have to take extrapolating with a pinch of salt, I want to come up with a bilinear extrapolation in case I have to evaluate outside the grid.
Say
is an evaluation point outside the predefined grid, and
is its closest point on the boundary. Then, the extrapoland is given by
where
is the value of Z at t, similarly for the partial derivatives.
I would compute the derivative of the extrapoland as

Is this gradient correct? I am uncertain about that since t, the closest point on the boundary, is also a function of (x,y). But I do not know how would one differentiate that.
댓글 수: 12
SA-W
2023년 6월 16일
Torsten
2023년 6월 16일
But lets assume I can compute the gradient everywhere inside the grid...
You need the gradient in the boundary point (t_x,t_y).
"I think it's more reasonable to extrapolate the value in (x,y) outside the grid as p(t_x,t_y)."
What do you mean by that?
I mean it's better to use a constant instead of a linear extrapolation. If a point (x,y) outside the grid domain is far apart, each kind of extrapolation tends to give unphysical results. And constant extrapolation is the petty evil.
SA-W
2023년 6월 16일
Torsten
2023년 6월 16일
Z_extrap(x,y) = Z(t_x,t_y) + dZ/dx (t_x,t_y) * (x - t_x) + dZ/dy (t_x,t_y) * (y - t_y)
That's why I asked about how you want to approximate the gradients in the boundary point (t_x,t_y).
But as already said: I wouldn't use linear extrapolation.
SA-W
2023년 6월 16일
SA-W
2023년 6월 16일
Determine the nearest point (t_x,t_y) to (x,y) on the boundary.
Depending on whether (t_x,t_y) is a corner point, a point on the vertical or a point on the horizontal boundary line, choose one-sided or central differences to approximate dZ/dx(t_x,t_y) and dZ/dy(t_x,t_y). If, e.g., (t_x,t_y) is on the lower horizontal boundary (not a corner point), approximate dZ/dx(t_x,t_y) = (Z(t_x+1,t_y)-Z(t_x-1,t_y))/(2*deltax) and dZ/dy(t_x,t_y) = (Z(t_x,t_y)-Z(t_x,t_y-1))/deltay (or with a one-sided difference approximation of higher order, if you like).
SA-W
2023년 6월 16일
But I think the issue is that Z(t_x,t_y), dZ/dx(t_x,t_y), and dZ/dy(t_x,t_y) are itself all functions of x and y because t_x,t_y depend on x and y.
No. It's a Taylor approximation of Z_extrap(x,y) of first-order with center point (t_x,t_y), the point nearest to (x,y).
SA-W
2023년 6월 16일
채택된 답변
추가 답변 (1개)
John D'Errico
2023년 6월 16일
편집: John D'Errico
2023년 6월 16일
Ugh. This is just a bad idea, Extrapolation in general is a bad thing to do. A better word is probably excrapolation. You will get exactly what you should expect from the name I just made up. There will be difficulties in trying to extrapolate, because if you try to extrapolate one cell, it is not going to be consistent with the extrapolant from the cell immediately next to it.
It is FAR better to use a tool that can at least try to intelligently extrapolate, using the shape of the surface near the boundary. In this case, I'll suggest my inpaint_nans tool, as found on the file exchange.
A = NaN(100,100);
A(30:70,30:70) = sin((X+Y)/5);
Ahat = inpaint_nans(A);
surf(Ahat)
hold on
H = surf(A);
H.FaceColor = 'r';

I doubt you can do too much better than that. It is actually not too bad, considering the extent of the extrapolation. (Yes, one of the things on my lengthy list of round-tuits is a better version of inpaint_nans for problems like this. But inpaint_nans is nearly 20 years old, and I fleshed out the idea for that improvement 20 years ago. Sigh.)
댓글 수: 2
SA-W
2023년 6월 16일
John D'Errico
2023년 6월 20일
편집: John D'Errico
2023년 6월 20일
The derivatives that you compute will not be very good, in the sense that they are themselves just based on local finite differences. And then you base the extrapolant on those local derivatives. Do you see this is a bad idea?
I'll strongly argue that you FIRST perform the extrapolation using a good tool like inpaint_nans. and THEN you can compute a derivative, from the results. This is better because inpaint_nans implicitly uses that same derivative information around the perimeter to infer the shape of the extrapolated surface. But it also uses all of that information at once, to infer a SMOOTHLY behaved extrapolant.
You are trying to solve the problem from the wrong direction. Hey, it is your choice of course. Of course, if you already know how to solve the problem, then why did you ask this question in the first place?
카테고리
도움말 센터 및 File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






