Mathematical Principles for Scientific Computing and Visualization  
http://www.farinhansford.com/books/scv
by Gerald Farin and Dianne Hansford

This notebook demonstrates interpolation.
Figure 8.4 was generated with this notebook.

Input: data values (x,y)_i i=1,n ... Here we have selected 6 values from y = sqrt(x) 
Output: the interpolating polynomial to the input values. Here then, we have a degree 5 polynomial.


See Chapter 8: Data Fitting for details.

Updated July 2008

Clear[x];
Clear[p];

(* Create six (x,y) values  -- Notice that y = sqrt(x) *)
vals = Table[{i^2,i},{i,0,5}]//N;

(* Let Mathematica create an interpolating polynomial *)
p[x_]=InterpolatingPolynomial[vals,x];

(SetDirectory[ToFileName[Extract["FileName"/.NotebookInformation[EvaluationNotebook[]],{1},FrontEnd`FileName]]];) 

(* Plot the function from which the "vals" were extracted and the interpolatin polynomial *)
(PLT=Plot[{(Sqrt[x]),p[x]},{x,0,25},PlotStyle->{{Thickness[0.01`],GrayLevel[0.5`]},{Thickness[0.01`]}},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},ColorOutput->GrayLevel]) 

(* Create a plot of the data points *)
(points=ListPlot[vals,PlotStyle->PointSize[0.03`],BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},ColorOutput->GrayLevel]) 

(* Put the plots together *)
(picfinal=Show[{PLT,points}]) 

(* Output to a postscript file *)
(Export["sqrt_int.eps",picfinal];)