Math 448/548 Cpt S 430/530 Assignment 2 Due February 9 1. Let
Total Page:16
File Type:pdf, Size:1020Kb
Math 448/548 Cpt S 430/530 Assignment 2 due February 9 1. Let A be a real n × n matrix. n (a) Let x 2 R and y = Ax. Show that for i = 1, . , n, yi (the ith component of y) satisfies n ! X jyi j ≤ jaij j kxk1: j=1 (b) Deduce that n ! X ky k ≤ max jaij j kxk 1 i 1 j=1 and n kAxk1 X max ≤ max jaij j: (1) x6=0 kxk i 1 j=1 (c) Show that equality holds in (1) by exhibiting an x for which n kAxk1 X = max jaij j: kxk i 1 j=1 (Hint: Choose an x whose entries are all ±1, with the signs care- fully chosen.) n ! X (d) Deduce that kAk = max jaij j 1 i j=1 2. Let 2 1 2 3 3 A = 4 4 5 6 5 : 7 8 9 (a) Prove by hand computation that A is singular. For example, you can show that the rows of A are linearly dependent. (b) Demonstrate that MATLAB, which uses floating-point arithmetic, does not notice that A is singular (although it does suspect that something is wrong). Use MATLAB commands like inv (inverse) and cond (condition number). 3. The Hilbert matrices are the most famous family of ill-conditioned ma- trices. The (i; j) entry of the n×n Hilbert matrix is hij = 1=(i+j −1). Using MATLAB, do the following for n = 4, 8, and 12. Generate the n×n Hilbert matrix. (MATLAB has a convenient command hilb that generates a Hilbert matrix.) Let z denote the vector of all ones, and let b = Az, where A is the Hilbert matrix. Then if we solve Ax = b, we should get the solution x = z in theory, but we don't because of roundoff errors. Solve Ax = b using MATLAB, and call the computed solutionx ^. (In MATLAB, xhat = A\b.) Compute the condition num- ber κ(A), the relative error kx^ − xk=kxk, and the relative residual kr k=kbk, where r = b − Ax^. Comment on your results. In the case n = 12, the computed solution is really quite inaccurate. (Important notice: I don't want to see a bunch of computer printout. Just show me the condition number, relative error and relative residual for the three cases.) 4. Perform the same experiment as in the previous problem for the case n = 12, but this time use a random 12 × 12 matrix. Before doing the experiment, check the condition number of the matrix. Chances are, it will be well conditioned. If it is not, generate another random matrix. Once you have a well conditioned one (condition number under 100, say), do the experiment. Comment on your results. 5. Compute the LU decomposition of the 12 × 12 Hilbert matrix. The matrix U is the upper-triangular matrix resulting from Gaussian elim- ination. Using format long, examine the matrix U, and notice that the matrix entries get smaller and smaller from top to bottom. They got that way by cancellation. (Just show me the last column of U (U(:,12)).) 6. Download the file lplcian.m from the homework page. This is a MAT- LAB function that I wrote that generates a large sparse matrix. Store this in your current folder. (Look at the commands and see if you can make out what they do.) When you type A = lplcian(n); from the MATLAB or Octave command line, a large, sparse discrete Laplacian matrix is generated. (a) Generate a matrix A as explained above. I recommend that you use n = 80, but you are welcome to adjust n upward or downward, depending on how fast your computer is and how patient you are, to make the matrix bigger or smaller. Use commands size(A), issparse(A), and nnz(A) to get information about your matrix. How large is it? How many nonzero entries does it have? How many zero entries does it have? Type spy(A) to get a spy plot of A. You don't need to turn in this or any other spy plots. (b) Compute the LU decomposition of A. How many nonzero entries do L and U have? How many zero entries do they have? Look at the spy plots of these matrices. (c) Build a random right-hand-side vector b of the appropriate size, and solve the system Ax = b, noting how long it takes: tic, x = A\b; toc. (d) Compute the inverse of A, noting how long it takes: tic, B = inv(A); toc. How many nonzero entries does B have? Look at a spy plot of B. This explains why we normally avoid computing A−1. Solve the system Ax = b using the inverse: y = B*b;. Com- pare this solution to the solution you got before: norm(x-y)/norm(x). (e) Estimate the condition number of A using the condest command, noting how long it takes. Now make a full (non-sparsely stored) version of A (C = full(A);) and compute its 1-condition number (cond(C,1)), noting how long it takes. How does the condition number compare with the estimate given by condest? Which took longer to obtain? (f) Compute the 2-condition number (cond(C,2)), noting how long it takes. Notice that this is different from the 1-condition number, but the two numbers are of roughly the same magnitude..