next up previous
Next: Further pachydermal spline fitting Up: tutorial10 Previous: Polynomial interpolation

Cubic splines

With irregular data we might well expect polynomial approximation to be very poor. Try instead now to use a cubic spline fit to the data. This uses nine different cubics, one between each adjacent pair of data points.

\bgroup\color{red}\framebox{\em ADD CODE TO FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroupAdd extra code to interpolate.m as follows. First create a new figure using the MATLAB command figure(2) . Also add the MATLAB commands

  clear
  figure(1)
  clf
at the beginning of your interpolate.m file. The clf command clears the current figure.

\bgroup\color{red}\framebox{\em ADD CODE TO FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroupThen calculate yspline using the MATLAB command

yspline=spline(x,y,xout) and plot yspline against xout . Compare this with the original data by using a plot command like plot(x,y,'ro') to plot the data points with red circles. Clearly the spline does a smooth job of interpolating the data: however, we should be wary of accepting this result as correct in all circumstances.



Subsections

Charlie Macaskill 2004-07-26