Lagrange Approximation

Takuichi Hirano (Tokyo Institute of Technology), November 5, 2008.
Mathematica 6

関数

f[x_]:=x*(x-1)*(x+1/2)

g1=Plot[f[x],{x,-1,2}]

離散化

n=4

xsamp=Table[-1+(2-(-1))*Random[],{i,1,n}]

ylis=f[xsamp]

fdisc=Table[{xsamp[[i]],ylis[[i]]},{i,1,Length[xsamp]}]

g2=ListPlot[fdisc,PlotStyle->{Red,PointSize[Large]}];
Show[g1,g2,PlotRange->All]

Lagrangeの補完多項式

g[x_]:=Sum[ylis[[i]]*((∏_(j=1)^(i-1))((x-xsamp[[j]])/(xsamp[[i]]-xsamp[[j]])))*((∏_(j=i+1)^n)((x-xsamp[[j]])/(xsamp[[i]]-xsamp[[j]]))),{i,1,n}]

g3=Plot[{f[x],g[x]},{x,-1,2}];
Show[g3,g2,PlotRange->All]