Nearest Interpolation in Matlab?

조회 수: 6 (최근 30일)
Nick Haufler
Nick Haufler 2016년 2월 18일
답변: John D'Errico 2016년 2월 18일
For the attached document can I get any confirmation as to whether my interpolation is correct or not. Should I be getting a negative number like I did or something else?

답변 (2개)

the cyclist
the cyclist 2016년 2월 18일
I think the -6cm/sec is correct, but I don't understand where the 3cm came from (and I think it is wrong). I'd give that a more careful look.

John D'Errico
John D'Errico 2016년 2월 18일
No. Linear interpolation between data points that are entirely positive, can NEVER yield a value that is negative. PERIOD. So you made a mistake.
In your title, it says something about nearest, so that too is in question, since nearest neighbor interpolation would also never yield negative numbers.
Since you did do some work there (even though there is NO MATLAB content here) I'll offer a better result.
@x = 6, we have y = 10
@x = 6.5, we have y = 7
So in MATLAB, I would do this:
t = (6.15 - 6)/(6.5 - 6);
y = 10*(1-t) + 7*t
y =
9.1
There the interpolation was written in the form of what one might call a convex linear combination of the function between those two endpoints.
Alternatively, we might choose to use a scheme that does interpolation by putting a line between those points. Effectively, the slope of the line is delta_y/delta_x, so using the point/slope form for a line, we can write the line as:
y(x) = y0 + (delta_y/delta_x)*(x-x0)
where the line is known to pass through the point (x0,y0).
10 + (7 - 10)/(6.5 - 6)*(6.15 - 6)
ans =
9.1
So that agrees with my first answer. Just lucky I guess. Or, we could do it as a function in MATLAB, since there must be some MATLAB content.
y_x = @(x) 10 + (7 - 10)/(6.5 - 6)*(x - 6);
y_x(6.15)
ans =
9.1
Whew! Again, the same answer. So I must be on a hot streak.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by