Interp1 is not woking
16 ビュー (過去 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 .
% 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 件のコメント
回答 (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.
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spline Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!