Example 7.  Find the "least squares cubic" that for the four data points  [Graphics:Images/LUFactorMod_gr_212.gif].  

Solution 7.

(a). Write down the linear system AC = B to be solved.

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




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

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

(b). Solve the linear system for the coefficients [Graphics:../Images/LUFactorMod_gr_216.gif] using our  LUfactor[n]  and  SolveLU[n]  subroutines.

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


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

(c). Construct the polynomial  p[x].  The coefficients are stored in the array  c  and the elements are [Graphics:../Images/LUFactorMod_gr_219.gif].

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


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

Of course we could do all this work in two lines by using Mathematica's built in  [Graphics:../Images/LUFactorMod_gr_222.gif]  procedure.

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


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

Notice that there appears to be a little "round-off" error creeping into the computation.  Lets "chop" it off.

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


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

We are done.

We can graph the polynomial, this is just for fun !

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


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

[Graphics:../Images/LUFactorMod_gr_229.gif]
[Graphics:../Images/LUFactorMod_gr_230.gif]
[Graphics:../Images/LUFactorMod_gr_231.gif]

Why is the "least-squares" polynomial a "perfect" power   [Graphics:../Images/LUFactorMod_gr_232.gif]?  Because the four data points are "perfect powers."
Of course we could do all this work in two lines by using Mathematica's built in  InterpolatingPolynomial[XY,x]  procedure.

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


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

The  InterpolatingPolynomial[XY,x]  procedure produces more accurate results if the answer should be an interpolating polynomial instead of a "least-squares" fit polynomial.

Caveat.  

    In numerical analysis we are concerned with round off error.  In the next example we will explore the "what if" scenario.  What will happen if the element  [Graphics:../Images/LUFactorMod_gr_235.gif]  is replaced with [Graphics:../Images/LUFactorMod_gr_236.gif] in the matrix ?  This change is merely [Graphics:../Images/LUFactorMod_gr_237.gif].  We will see that this will result is tremendous changes in the coefficients [Graphics:../Images/LUFactorMod_gr_238.gif].  The numerical algorithms are correct, it is a problem with the matrix, it has a large condition number and is ill conditioned.  We need to be aware of these pitfalls.

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



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

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2004