Extrapolation of 2 end points in interp1 instead of single scalar value

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Extrapolation of 2 end points in interp1 instead of single scalar value

Han Yichou

Hi,


I am trying to interpolate the points within a dataset but to extrapolate any x values outside of the dataset range by assuming the 2 end points continue with the same y value. I am using interp1 to carry out the interpolation. However, I see that Octave only allows extrapolation of a single scalar value. Can someone advise how I can extrapolate using 2 separate values instead?


Regards,

Han


Sent from Outlook



Reply | Threaded
Open this post in threaded view
|

Re: Extrapolation of 2 end points in interp1 instead of single scalar value

Sebastian Schöps
Han Yichou wrote
> I am trying to interpolate the points within a dataset but to extrapolate
> any x values outside of the dataset range by assuming the 2 end points
> continue with the same y value. I am using interp1 to carry out the
> interpolation. However, I see that Octave only allows extrapolation of a
> single scalar value. Can someone advise how I can extrapolate using 2
> separate values instead?

How do you want to interpolate? If you do constant interpolation, then the
following does immediately work
>x=[1 2 3];
>y=x.^2;
>interp1(x,y,'nearest','extrap',[0 1 3 4])
1   1   9   9

If you want to use linear interpolation but constant extrapolation, then you
can exploit the linearity of the interpolation by adding two virtual points
>x= [0 x 4];
>y=[y(1) y y(end)]
>interp1(x,y,'linear','extrap',[0 1 3 4])
1   1   9   9

If you want to use splines, than you may have to create a pp-structure with
"interp1(...,'pp')" and then you may add your own (constant) polynomial
pieces to it, see mkpp and unmkpp.

Sebastian




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html