(* *) (* Numerical Mathematics and Computing, Fifth Edition *) (* Ward Cheney & David Kincaid *) (* Brooks/Cole Publ. Co. *) (* (c) 2003 *) (* No warranties implied or expressed. *) (* File: runge_fcn *) (* polynomial interpolation: Runge function - equal spacing*) F[x_]:=1/(1 + x*x) a=-5; b=5; n=8; h=(b-a)/n; data = Table[N[{x,F[x]}], {x, a, b, h}] plotdata = ListPlot[data] Fit[data, Table[x^i, {i,0,n}],x] plotcurve=Plot[%,{x,a,b}] Show[plotdata, plotcurve] (* polynomial interpolation: Runge function - Chebyshev spacing*) F[x_]:=1/(1 + x*x) a=-5; b=5; n=8; h=(b-a)/n; data = Table[N[{0.5*((a+b)+(b-a)*Cos[(i/n)*Pi]), F[0.5*((a+b)+(b-a)*Cos[(i/n)*Pi])], {1, 0, n}] plotdata = ListPlot[data] Fit[data, Table[x^i, {i,0,n}],x] plotcurve=Plot[%,{x,a,b}] Show[plotdata, plotcurve]