Limitations of Lagrange Polynomial Interpolation

Let's look at the function Cos[x]^10 on the interval from -2 to 2.

In[20]:=

  f[t_]:=If[t>=-2 && t<=2,Cos[t]^10,0]

In[21]:=

  original=Plot[f[x],{x,-2,2},PlotRange->{-1,1}];

Let's test Lagrange Polynomial Interpolation by trying more and more points:

In[22]:=

  x={-2,0,2}
  y={Cos[-2]^10,1,Cos[2]^10}

Out[22]=

  {-2, 0, 2}

Out[23]=

         10           10
  {Cos[2]  , 1, Cos[2]  }

In[24]:=

  p2[t_]:=lagrangepoly[t,x,y];
  p2[t]
  p2plot=Plot[p2[t],{t,-2,2}];
  Show[original,p2plot];

Out[24]=

                                         10
  -((-2 + t) (2 + t))   (-2 + t) t Cos[2]
  ------------------- + ------------------- + 
           4                     8
   
                    10
    t (2 + t) Cos[2]
    ------------------
            8

In[25]:=

  x={-2,-1,0,1,2}
  y=Cos[x]^10

Out[25]=

  {-2, -1, 0, 1, 2}

Out[26]=

         10        10           10        10
  {Cos[2]  , Cos[1]  , 1, Cos[1]  , Cos[2]  }

In[27]:=

  p4[t_]:=lagrangepoly[t,x,y];
  p4[t]
  p4plot=Plot[p4[t],{t,-2,2}];
  Show[original,p4plot];

Out[27]=

  (-2 + t) (-1 + t) (1 + t) (2 + t)
  --------------------------------- - 
                  4
   
                                      10
    (-2 + t) (-1 + t) t (2 + t) Cos[1]
    ------------------------------------ - 
                     6
   
                                     10
    (-2 + t) t (1 + t) (2 + t) Cos[1]
    ----------------------------------- - 
                     6
   
                                       10
    (-1 - t) (-2 + t) (-1 + t) t Cos[2]
    ------------------------------------- + 
                     24
   
                                     10
    (-1 + t) t (1 + t) (2 + t) Cos[2]
    -----------------------------------
                    24

In[28]:=

  x={-2,-2+2/3,-2+4/3,0,2-4/3,2-2/3,2}
  y=Cos[x]^10

Out[28]=

         4     2      2  4
  {-2, -(-), -(-), 0, -, -, 2}
         3     3      3  3

Out[29]=

         10      4 10      2 10         2 10      4 10
  {Cos[2]  , Cos[-]  , Cos[-]  , 1, Cos[-]  , Cos[-]  , 
                 3         3            3         3
   
          10
    Cos[2]  }

In[30]:=

  p6[t_]:=lagrangepoly[t,x,y];
  p6[t]
  p6plot=Plot[p6[t],{t,-2,2}];
  Show[original,p6plot];

Out[30]=

                   4          2        2       4
  (-81 (-2 + t) (-(-) + t) (-(-) + t) (- + t) (- + t) 
                   3          3        3       3
   
                                         4          2
       (2 + t)) / 256 + (243 (-2 + t) (-(-) + t) (-(-) + t) 
                                         3          3
   
          4                  2 10
       t (- + t) (2 + t) Cos[-]  ) / 1024 + 
          3                  3
   
                     4          2       4
    (243 (-2 + t) (-(-) + t) t (- + t) (- + t) (2 + t) 
                     3          3       3
   
           2 10
       Cos[-]  ) / 1024 - 
           3
   
                     4          2          2
    (243 (-2 + t) (-(-) + t) (-(-) + t) t (- + t) (2 + t) 
                     3          3          3
   
           4 10
       Cos[-]  ) / 2560 - 
           3
   
                     2          2       4
    (243 (-2 + t) (-(-) + t) t (- + t) (- + t) (2 + t) 
                     3          3       3
   
           4 10
       Cos[-]  ) / 2560 + 
           3
   
                    4          2          2       4
    (81 (-2 + t) (-(-) + t) (-(-) + t) t (- + t) (- + t) 
                    3          3          3       3
   
             10
       Cos[2]  ) / 5120 + 
   
           4          2          2       4
    (81 (-(-) + t) (-(-) + t) t (- + t) (- + t) (2 + t) 
           3          3          3       3
   
             10
       Cos[2]  ) / 5120

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.

Up to First Attempt: Lagrange Polynomial Interpolation