Interp1 is not woking
16 views (last 30 days)
Show older comments
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....
0 Comments
Answers (2)
Bruno Luong
on 19 Jan 2023
Edited: Bruno Luong
on 19 Jan 2023
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.
0 Comments
Jiri Hajek
on 19 Jan 2023
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.
0 Comments
See Also
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!