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!






