next up previous
Next: About this document ... Up: Math 0250 Computer Assignment Previous: Linear Systems

Stuff to Hand In

These questions relate to Hilbert matrices. A Hilbert matrix is always square, and the entry in row i column j is $\frac{1}{i+j-1}$.For example, here's a $4\times4$ Hilbert matrix:

\begin{displaymath}
H_4 = \left[\begin{array}
{rrrr}
 1&\frac12&\frac13&\frac14\...
 ...&\frac16\  \frac14&\frac15&\frac16&\frac17
 \end{array}\right]\end{displaymath}

You can produce an $n\times n$ Hilbert matrix with Matlab or Octave with
  hilb(n)
1.
Build a $5\times5$ Hilbert matrix with
  n = 5;
  H = hilb(n);
(The reason for introducing n is so that you can recycle the same commands later with a larger Hilbert matrix by just changing the value of n.) Next, enter the column matrix

\begin{displaymath}
B = \left[\begin{array}
{r}
 1\ 0\ 0\ 0\ 0
 \end{array}\right]\end{displaymath}

with
  B = [1;zeros(n-1,1)];
Solve the equation HX=B by both Gaussian elimination and left division. Report the results.
2.
Let's repeat the performance from problem 1 with a bigger Hilbert matrix. To get started, enter a $20\times20$ Hilbert matrix H, and a $20\times1$ forcing matrix B with 1 as its first entry, and zeros everywhere else. Here's how to do it with minimal additional typing (assuming that you've just finished problem 1). Enter
  n = 20;
Now push the up arrow key several times until you see the input line that you used to define H in problem 1, and hit the enter key to enter it again. Since you've now changed the value of n to 20, you should now get a $20\times20$ Hilbert matrix. Do the same thing to redefine B. Now solve the system HX=B, first using row reduction, and again using left division, and compare your answers. You may have some trouble reading off the results. Here's how to organize the computer display to make it easier. Save the result of the row reduction in a variable A1:
  A1 = rref([H,B]);
and save the result of left division in a variable A2:
  A2 = H\B;
You can now display the two column vectors next to each other with
  [A1(1:n,n+1),A2]
Do it, and report on how the two solutions compare. It's not necessary to report all 40 numbers. Just write a sentence or two saying how the two answers compare.

3.
You can get an accurate solution to the system HX=B from 2 with
  A3 = invhilb(n) * B;
Compare this to the two results you got in 2 and report the results.

The point of this exercise is that numerical calculations with computers can be fraught with potential pitfalls. The Hilbert matrix is an example of an ill conditioned matrix. Numerical calculations with ill conditioned matrices often give inaccurate results because of compounded truncation errors.


next up previous
Next: About this document ... Up: Math 0250 Computer Assignment Previous: Linear Systems
Frank Beatrous
1/20/1998