Math 171 - Alexiades
                  HW: Polynomial fitting to data
Consider some data points, e.g.
      x = [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0];
      y = [0.01 0.1 0.3 0.5 0.5 0.6 0.6 0.3 0.1 0.3 0.04];
  • Fit a quadratic, find the LSerror, and plot:
          P2 = polyfit(x,y,2);   %% (coefficients of) 2nd degree polynomial best fitting the data
          y2 = polyval(P2, x);   %% evaluate P2 at x-values
          E2 = sum( (y-y2).^2 )   %% LS error
          plot(x,y,'ko', x, y2, 'r-*' )

  • Similarly, fit a 4th degree polynomial, find E4, and plot

  • Similarly, fit a 10th degree polynomial, find E10, and plot
      With 11 points, P10 is the highest degree that can be found and it interpolates the data (passes through the points).