Azzera filtri
Azzera filtri

Interp1 is not woking

19 visualizzazioni (ultimi 30 giorni)
도연 원
도연 원 il 19 Gen 2023
Modificato: Bruno Luong il 19 Gen 2023
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....

Risposte (2)

Bruno Luong
Bruno Luong il 19 Gen 2023
Modificato: Bruno Luong il 19 Gen 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.

Jiri Hajek
Jiri Hajek il 19 Gen 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.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by