Limitations of Lagrange Polynomial Interpolation
f[t_]:=If[t>=-2 && t<=2,Cos[t]^10,0]
original=Plot[f[x],{x,-2,2},PlotRange->{-1,1}];Let's test Lagrange Polynomial Interpolation by trying more and more points:
x={-2,0,2}
y={Cos[-2]^10,1,Cos[2]^10}
p2[t_]:=lagrangepoly[t,x,y];
p2[t]
p2plot=Plot[p2[t],{t,-2,2}];
Show[original,p2plot];
x={-2,-1,0,1,2}
y=Cos[x]^10
p4[t_]:=lagrangepoly[t,x,y];
p4[t]
p4plot=Plot[p4[t],{t,-2,2}];
Show[original,p4plot];
x={-2,-2+2/3,-2+4/3,0,2-4/3,2-2/3,2}
y=Cos[x]^10
p6[t_]:=lagrangepoly[t,x,y];
p6[t]
p6plot=Plot[p6[t],{t,-2,2}];
Show[original,p6plot];The Lagrange polynomials are becoming better estimates, but there are oscillations at the ends. There are some remedies to this. One of the must used is Cubic Spline Interpolation.