Example 7. Find the
"least squares cubic" that for the four data
points
.
Solution 7.
(a). Write down the linear system AC = B to be solved.
(b). Solve the linear system
for the coefficients
using our LUfactor[n] and SolveLU[n] subroutines.
(c). Construct the
polynomial p[x]. The
coefficients are stored in the array c and
the elements are
.
Of course we could do all this work in two lines by using
Mathematica's built in
procedure.
Notice that there appears to be a little "round-off" error creeping into the computation. Lets "chop" it off.
We are done.
We can graph the polynomial, this is just for fun !
![[Graphics:../Images/LUFactorMod_gr_228.gif]](../Images/LUFactorMod_gr_228.gif)
Why is the "least-squares" polynomial a "perfect"
power
? 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.
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
is
replaced with
in the matrix ? This change is merely
. We
will see that this will result is tremendous changes in the
coefficients
. 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.
(c) John H. Mathews 2004