MATLAB: How to get a accurate or near accurate extrapolation in interp1

image processinginterpolationMATLABsignal processing

if 'extrap' extrapolation is used, the new vector doesn't give expected result. If zero is filled in the extrapolation points, the result somewhat matches the expected result.
Is there any other extrapolation algorithm which can give better accuracy?
program here,
a=[ 2 4 7 9 3 6 8]; % vector
xold=linspace(3,9,7); % old x axis
xnew=linspace(1,11,11); % new x axis
anew=interp1(xold,a,xnew,'spline','extrap'); % new vector
% anew=interp1(xold,a,xnew,'spline',0); % new vector

Best Answer

Extrapolating a spline is insane, dangerous, crazy, random ... Just pick your word. They all apply.
Accurate is hardly ever a word that will apply, at least in context of a meaningful sentence about extrapolation and splines. Ok, I can do that if I try. Perhaps this: "Extrapolation of a spline beyond the support of the data will rarely if ever be an accurate predictor of the underlying function."
I once wrote a routine that would take an existing spline, then creating a new spline that extrapolated the old. It allowed the user to provide information about how one should do the extrapolation. I've wanted to re-write code for that purpose many times. On the round-tu-it list.
The point is that you cannot extrapolate a cubic segment accurately unless you know how that extrapolant should behave. Should it be monotonic? Linear? Could it roll over? Approach an asymptote?
In general, even when I wrote that code many years ago, I usually recommended that it was better to build the spline FIRST over the entire domain of interest (including the extrapolated domain) using the necessary information. Since you can do that using my SLM toolbox, I've never really had the desire to re-write the extrapolant code.
So my recommendation is that you use SLM to build the spline in the first place, where you build the spline out as far as necessary. Apply all necessary information about the shape of the spline in the extrapolated region when you build the spline. Then you can evaluate that spline to your heart's content.
Related Question