Example 4. Compare
the "discrete least squares approximation" and "continuous least
squares approximation."
4 (a). Use the
function
, on
the interval
.
Solution 4 (a).
![[Graphics:../Images/LegendrePolyMod_gr_132.gif]](../Images/LegendrePolyMod_gr_132.gif)
![[Graphics:../Images/LegendrePolyMod_gr_134.gif]](../Images/LegendrePolyMod_gr_134.gif)
![]()
![[Graphics:../Images/LegendrePolyMod_gr_136.gif]](../Images/LegendrePolyMod_gr_136.gif)
![[Graphics:../Images/LegendrePolyMod_gr_137.gif]](../Images/LegendrePolyMod_gr_137.gif)
![[Graphics:../Images/LegendrePolyMod_gr_138.gif]](../Images/LegendrePolyMod_gr_138.gif)
![[Graphics:../Images/LegendrePolyMod_gr_139.gif]](../Images/LegendrePolyMod_gr_139.gif)
![[Graphics:../Images/LegendrePolyMod_gr_140.gif]](../Images/LegendrePolyMod_gr_140.gif)
![[Graphics:../Images/LegendrePolyMod_gr_141.gif]](../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_143.gif]](../Images/LegendrePolyMod_gr_143.gif)
The condition number of the above system can be determined by Mathematica.
![]()
Fact. Given
the linear system
. If
are
input with machine precision then a bound for the error in the
computed solution
is
given by
where
is machine epsilon for the
computer. The computed
solution
loses
about
decimal
digits of accuracy relative to precision of input.
![[Graphics:../Images/LegendrePolyMod_gr_154.gif]](../Images/LegendrePolyMod_gr_154.gif)
Caveat. Although
Mathematica uses extended precision sixteen digit numbers,
there is a possibility that the solution
might
not have this much accuracy.
Remark. When
solving the continuous least squares approximation on the interval
,
the matrix of coefficients
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
by
directly setting up the matrix
vector
. This
is just for fun !
![[Graphics:../Images/LegendrePolyMod_gr_163.gif]](../Images/LegendrePolyMod_gr_163.gif)
This is the same as we obtained previously.
(c) John H. Mathews 2005