![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1268425/image.png)
Interp1 is not woking
10 次查看(过去 30 天)
显示 更早的评论
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 .
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1268405/image.png)
% 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...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1268410/image.png)
I don't know what is causing this issue. Did I do something wrong? I just need some extrapolated smooth curve here....
0 个评论
回答(2 个)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1268425/image.png)
Use 'linear' method, you'll have a straight line extrapolation, which is more stable than spline.
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!