Module for Least Squares Polynomials

Check out the new Numerical Analysis Projects page.

 

Least-Squares Polynomial Curve Fitting.  To construct the least squares polynomial of degree  m  of the form  

    
[Graphics:Images/LeastSquaresPolynomialMod_gr_1.gif]
    
that fits the n data points  
[Graphics:Images/LeastSquaresPolynomialMod_gr_2.gif].  

The matrix form for the normal equations for least squares polynomial curve fitting is  

 

[Graphics:Images/LeastSquaresPolynomialMod_gr_3.gif][Graphics:Images/LeastSquaresPolynomialMod_gr_4.gif]  

 

One thing is certain, to find the least squares polynomial the above linear system must be solved. There are various linear system solvers that could be used for this task.  However, since this is such an important computation, most mathematical software programs have a built-in subroutine for this purpose.  In Mathematica it is called the "Fit" procedure.  Fit[data, funs, vars] finds a least­squares fit to a list of data as a linear combination of the functions funs of variables vars.

We will check the "closeness of fit" with the RMS measure for the "error in the fit."

[Graphics:Images/LeastSquaresPolynomialMod_gr_5.gif]

Example 1.  Find the polynomial curve fit of degree  n = 2  for the following points.
Use Mathematica to find the "Least Square Quadratic", and find the RMS error.
Solution 1.

 

Example 2.  Find the polynomial fits of degree  n = 3  for the data points in the previous example.
Use Mathematica to find the "Least Square Cubic", and find the RMS error.
Solution 2.

 

Example 3.  Find the polynomial fits of degree  n = 4  for the data points in the previous example.
Use Mathematica to find the "Least Square Quartic", and find the RMS error.
Solution 3.

 

Example 4.  Find the polynomial curve fit of degree  n = 5  for the following points.
Use Mathematica to find the "Least Square Quintic", and find the RMS error.
Solution 4.

 

Example 5.  Why is the RMS error for  [Graphics:Images/LeastSquaresPolynomialMod_gr_34.gif]  essentially zero ?
Solution 5.

 

Curve fitting is nice for data interpolation.  

[Graphics:Images/LeastSquaresPolynomialMod_gr_40.gif]

[Graphics:Images/LeastSquaresPolynomialMod_gr_41.gif]

Warning.  You are on your own if you use curve fitting for data extrapolation.  Things might "blow up" outside the interval where the data is located.  Too often this is the case.

[Graphics:Images/LeastSquaresPolynomialMod_gr_42.gif]

[Graphics:Images/LeastSquaresPolynomialMod_gr_43.gif]

Caution for polynomial curve fitting.   Something goes radically wrong if the data is radically "NOT polynomial."  This phenomenon is called "polynomial wiggle."  

 

Example 6.  Find the least squares polynomial fits of degree n = 2, 3, 4, 5 for the points
(0.25, 23.1), (1.0 , 1.68),  (1.5 , 1.0), (2.0 , 0.84), (2.4 , 0.826), (5.0 , 1.2576)
Solution 6.

 

 

Old Lab Project (Least Squares Polynomials  Least Squares Polynomials).  
Internet hyperlinks to an old lab project.  

 

Research Experience for Undergraduates

Least Squares Polynomials  Least Squares Polynomials  
Internet hyperlinks to web sites and a bibliography of articles.  

   

Downloads (Least Squares Polynomials Least Squares Polynomials).  
Download this Mathematica notebook.  

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2003