Example 4. Find the
continuous least squares polynomial of degree n=4
that approximates the function
over
the interval
.
Solution 4.
The set of functions is
.
The inner product ![]()
Since i and j are positive integers, this can be simplified with the command
Therefore, the Gram matrix G is the 5×5 Hilbert matrix.
The inverse
is the matrix M.
Enter the function
, and
the set of functions
,
and compute
for
,
and write down the linear system GC = Y to be
solved.
Solve the linear system for the coefficients
using
and the computation
.
Construct the polynomial p[x]. The
coefficients are stored in the array c and
the elements are
.
We are done.
We can graph the polynomial, this is just for fun !
![[Graphics:../Images/InverseMatrixMod_gr_219.gif]](../Images/InverseMatrixMod_gr_219.gif)
![[Graphics:../Images/InverseMatrixMod_gr_224.gif]](../Images/InverseMatrixMod_gr_224.gif)
![[Graphics:../Images/InverseMatrixMod_gr_229.gif]](../Images/InverseMatrixMod_gr_229.gif)
(c) John H. Mathews 2004