Examples

In[12]:=
  x={-1.1,2.1,3.5}
  y={1.3,2.5,-1.6}

Out[12]=

  {-1.1, 2.1, 3.5}

Out[13]=

  {1.3, 2.5, -1.6}

In[14]:=

  p2[t_]:=lagrangepoly[t,x,y];
  p2[t]

Out[14]=

  0.0883152 (-3.5 + t) (-2.1 + t) - 
   
    0.558036 (-3.5 + t) (1.1 + t) - 
   
    0.248447 (-2.1 + t) (1.1 + t)

In[15]:=

  plot1=Plot[p2[t],{t,-2,4}];
  plot2=ListPlot[Table[{x[[i]],y[[i]]},{i,1,3}],PlotStyle->{RGBColor[1,0,0],PointSize[.02]}];
  Show[plot1,plot2];

In[16]:=

  Clear[x,y]
  x={1,-2,3,-1}
  y={0,16,-2,1}

Out[16]=

  {1, -2, 3, -1}

Out[17]=

  {0, 16, -2, 1}

In[18]:=

  p3[t_]:=lagrangepoly[t,x,y];
  p3[t]

Out[18]=

  16 (1 - t) (-3 + t) (1 + t)   (1 - t) (-3 + t) (2 + t)
  --------------------------- - ------------------------ - 
              15                           8
   
    (-1 + t) (1 + t) (2 + t)
    ------------------------
               20

In[19]:=

  plot1=Plot[p3[t],{t,-3,4},PlotRange->{-8,17}];
  plot2=ListPlot[Table[{x[[i]],y[[i]]},{i,1,4}],PlotRange->{-8,17},PlotStyle->{RGBColor[1,0,0],PointSize[.02]}];
  Show[plot1,plot2];

Up to First Attempt: Lagrange Polynomial Interpolation