You can produce an Hilbert matrix with Matlab or Octave 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
B = [1;zeros(n-1,1)];Solve the equation HX=B by both Gaussian elimination and left division. Report the results.
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.
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.