% Interpolation
% Interpolation is similar to curve fitting, in that it allows one to represent discrete data with a continuous function. However it differs in the requirement that interpolating functions must pass through all the data points. The algorithms employed in Matlab achieve this by piecing together a series of functions, rather than trying to produce a single function that
% Polynomial Interpolation
% The primary interpolating function in Matlab is interp1. It is capable of producing  interpolating functions with the following properties (this is not a comprehensive list):
% Linear – with straight line fits from point to point
% Cubic – using cubic Hermite interpolation
% Spline - with a cubic polynomial through triplets of points
% If we begin with a dataset of x and y data, with y being the dependent variable, then the interp1 function is called as:
% yi = interp1(x,y,xi,’linear’)
% Where the outcome is interpolated values of the dependent variable evaluated at the points in the vector xi. This will produce values using linear interpolation. The last argument in this call can be varied to switch to different interpolation algorithms.
% Sample code for using this routine might be as follows:

time=0:10;
temps=[72.5 78.1 86.4 92.3 110.6 111.5 109.3 110.2 110.5 109.9 110.2];
plot(time,temps,'o')
xlabel('Time (s)')
ylabel('Temperature (F)')
plotvals=0:0.1:10;
yvals=interp1(time,temps,plotvals,'linear');
set(gca,'FontSize',20)
hold on
plot(plotvals,yvals,'LineWidth',2)
yvals=interp1(time,temps,plotvals,'pchip');
plot(plotvals,yvals,'r','LineWidth',2)
yvals=interp1(time,temps,plotvals,'spline');
plot(plotvals,yvals,'g','LineWidth',2)
hold off

% © James Blanchard, University of Wisconsin-Madison, blanchard@engr.wisc.edu