Interp1 is not woking

14 次查看(过去 30 天)
도연 원
도연 원 2023-1-19
Hi, guys. Always thanks for the help!
I have encountered problem on interpolation.
Using function 'interp1' and option as 'extrap' and 'spline' method, interp1 is not working properly.
Variable is in the attached. And below is the code.
% plot(v1, f1) result is below;
% but I want to extend x-axis -0.01 ~ 0, so try to interpolate and extrapolate .
% Code that I used is below;
v1r = -0.01:0.0001:0;
f1r = interp1(v1, f1, v1r, 'spline', 'extrap')
% however when plot(v1r, f1r) this returns plot below...
I don't know what is causing this issue. Did I do something wrong? I just need some extrapolated smooth curve here....

回答(2 个)

Bruno Luong
Bruno Luong 2023-1-19
编辑:Bruno Luong 2023-1-19
Extrapolation is notoriously unstable. So there is no surprise here.
v1r = -0.01:0.00001:0
f1r = interp1(v1, f1, v1r, 'spline', 'extrap')
plot(v1r, f1r)
xline(min(v1))
axis([-0.0100 -0.0092 -1.0000 -0.3361])
the extrapolation is fine but shoot over the sky because the second/thord derivative of the end point is large.
Use 'linear' method, you'll have a straight line extrapolation, which is more stable than spline.

Jiri Hajek
Jiri Hajek 2023-1-19
Hi, as you have already noticed, there is no good general extrapolation method, which you seem to have expected. That is why the interpolators in MATLAB have options for preferred method of extrapolation (see documentation of interp1). And note, there is no extrapolator in MATLAB, only interpolators, for a good reason...
Your interpolation method is in essence a piecewise polynomial., which always becomes very imprecise outside of your input data (see Taylor series). If you need an extrapolation method for your 1D data, it is always better to do regression with a single global function that will cover your whole input space.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by