MATLAB: Data: Interp1 spline and cubic method

approximationscubicinterp1polyfitpolyvalspline

Im just trying to figure out how I would use the Interp1 function with the spline method and the Interp1 withe cubic method for approximation. Are the Interp1 function and some call to spline linked in the same code.
For example how would you approximate this data using the Interp1 function and spline method/ whats the difference between the cubic method.
year=[1;2;3;4;5;6;7;8;9;10];
pop=[5;10;15;20;25;30;35;40;50;60];

Best Answer

how would you approximate this data using the Interp1 function and spline method
For example,
year=[1;2;3;4;5;6;7;8;9;10];
pop=[5;10;15;20;25;30;35;40;50;60];
interp1(year,pop, 2.5,'spline')
whats the difference between the cubic method.
It's just a different interpolation kernel. The cubic method will gives an interpolated curve that is only once-differentiable, but it will follow the shape of the data more closely than a spline interpolation. Example:
y=[zeros(1,10) 1 1.15 1.15 1 zeros(1,10)];
x=1:numel(y);
xq=linspace(1,numel(y),1000);
plot(x,y,'o',xq,interp1(y,xq,'spline'), xq, interp1(y,xq,'cubic'))
legend('', 'Spline','Cubic')
Related Question