Example 4.  Compare the "discrete least squares approximation" and "continuous least squares approximation."  
4 (a).  Use the function  [Graphics:Images/LegendrePolyMod_gr_127.gif],  on the interval  [Graphics:Images/LegendrePolyMod_gr_128.gif].  

Solution 4 (a).

[Graphics:../Images/LegendrePolyMod_gr_131.gif]



[Graphics:../Images/LegendrePolyMod_gr_132.gif]

 

 

 

[Graphics:../Images/LegendrePolyMod_gr_133.gif]




[Graphics:../Images/LegendrePolyMod_gr_134.gif]

[Graphics:../Images/LegendrePolyMod_gr_135.gif]

[Graphics:../Images/LegendrePolyMod_gr_136.gif]

[Graphics:../Images/LegendrePolyMod_gr_137.gif]

[Graphics:../Images/LegendrePolyMod_gr_138.gif]

[Graphics:../Images/LegendrePolyMod_gr_139.gif]

[Graphics:../Images/LegendrePolyMod_gr_140.gif]

[Graphics:../Images/LegendrePolyMod_gr_141.gif]

 

 

Warning.  We must proceed with caution when using a least squares method because the linear system might be ill conditioned, i.e. the solution is highly sensitive to round off errors in the matrix and vector.  Let us investigate the situation for this example.

[Graphics:../Images/LegendrePolyMod_gr_142.gif]


[Graphics:../Images/LegendrePolyMod_gr_143.gif]

 

 

    The condition number of the above system can be determined by Mathematica.

[Graphics:../Images/LegendrePolyMod_gr_144.gif]


[Graphics:../Images/LegendrePolyMod_gr_145.gif]

 

Fact.  Given the linear system  [Graphics:../Images/LegendrePolyMod_gr_146.gif].  If   [Graphics:../Images/LegendrePolyMod_gr_147.gif]  are input with machine precision then a bound for the error in the computed solution  [Graphics:../Images/LegendrePolyMod_gr_148.gif]  is given by

        
[Graphics:../Images/LegendrePolyMod_gr_149.gif]

where
[Graphics:../Images/LegendrePolyMod_gr_150.gif] is machine epsilon for the computer.  The computed solution  [Graphics:../Images/LegendrePolyMod_gr_151.gif]  loses about  [Graphics:../Images/LegendrePolyMod_gr_152.gif]  decimal digits of accuracy relative to precision of input.

[Graphics:../Images/LegendrePolyMod_gr_153.gif]



[Graphics:../Images/LegendrePolyMod_gr_154.gif]

 

Caveat.  Although Mathematica uses extended precision sixteen digit numbers, there is a possibility that the solution  [Graphics:../Images/LegendrePolyMod_gr_155.gif]  might not have this much accuracy.  

Remark.  When solving the continuous least squares approximation on the interval [Graphics:../Images/LegendrePolyMod_gr_156.gif], the matrix of coefficients  [Graphics:../Images/LegendrePolyMod_gr_157.gif]  is known to be a Hilbert matrix which is the classic example of an ill-conditioned matrix.  

We are really done.  

Aside.  We can calculate the coefficients  [Graphics:../Images/LegendrePolyMod_gr_158.gif]  by directly setting up the matrix  [Graphics:../Images/LegendrePolyMod_gr_159.gif] vector [Graphics:../Images/LegendrePolyMod_gr_160.gif].  This is just for fun !  

[Graphics:../Images/LegendrePolyMod_gr_161.gif]





[Graphics:../Images/LegendrePolyMod_gr_162.gif]

[Graphics:../Images/LegendrePolyMod_gr_163.gif]

This is the same as we obtained previously.  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2005