Cubic Spline example



Class example:  plot cos(x)^10 using fine partition, coarse partition
with polynomial interpolation, and cubic spline.

   fine partition;

   >> x1 = -2:.05:2;
   >> y1 = (cos(x1)).^10;
   >> plot(x1,y1)

   coarse partition:

   >> x = -2:.5:2;
   >> y = (cos(x)).^10;
   >> f = polyfit(x,y,8)

   f =

       0.2525   -0.0000   -1.9414    0.0000    4.6531   -0.0000
       -3.9621    0.0000    1.0000

       >> y2 = polyval(f,x1);

  Plot fine and coarse partition on same graph at the fine
       partition points.

  >> plot(x1,y1,x1,y2)
  >> grid
  >> hold
  Current plot held

  cubic spline using the coarse partition points as knots

  >> yy = spline(x,y,x1);
  >> plot(x1,yy,'o')
      
  

URL:

by Charles Tier