0

I need to extrapolate values

values = [4.7725677013567795e-25,5.259671597595681e-25,5.271571307092517e-25,5.804522928756955e-25,5.817596178596506e-25,6.400225475961127e-25,6.414575757297374e-25,7.05099062804588e-25,7.066729446412066e-25];

when i run

x = [1:9];
valuesextra = interp1(x,values,[10:3120],'spline','extrap');

First of all, the extrapolated values get smaller, whereas they should get larger, and secondly the sign of the received values flips after the first value and i get

4.34358964678642e-25    -3.23663133644058e-25   -1.77921360688784e-24   -4.14411271161367e-24 ...

I have done similar extrapolations with similar data sets where I received a correct extrapolation. What is wrong here? Btw: the data set actually is 450 long not 9, i just posted this minimal example which produces such a flip of the sign.

jonnyx
  • 345
  • 2
  • 16

1 Answers1

2

Your data look like "steps" enter image description here

that's why could better use fit function instead of interp1

The code could look as follows:

values = [4.7725677013567795e-25,5.259671597595681e-25,5.271571307092517e-25,5.804522928756955e-25,5.817596178596506e-25,6.400225475961127e-25,6.414575757297374e-25,7.05099062804588e-25,7.066729446412066e-25]';
x = (1:9)';
figure();
subplot(2,1,1)
plot(x,values,'.b',x,values,'-g')
hold all;

f = fit(x, values, 'poly1');
plot(f)

xx = (10:3120);
yy = f.p1*xx + f.p2;
subplot(2,1,2)
plot(x,values,'.b',x,values,'-g');
hold all;
plot(xx,yy,'.k',xx,yy,'--r')

You can choose another fitting function, see help for fit, to adjust the yy function appropriately

'cubicinterp' - Piecewise cubic interpolation

'smoothingspline' - Smoothing spline (curve)

ARTE
  • 118
  • 6