# 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 .For example, here's a Hilbert matrix:

You can produce an Hilbert matrix with Matlab or Octave with
  hilb(n)

1.
Build a 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

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 Hilbert matrix H, and a 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 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.