
Math 477/577 — Computer Assignment 3, due Oct.12, 2006
1. Write a Matlab function [Q,R] = mgs(A) (see the discussion in the classnotes of stability of
the Gram-Schmidt algorithms) that computes a reduced QR factorization A=ˆ
Qˆ
Rof an m×n
matrix Awith m≥nusing modified Gram-Schmidt orthogonalization. The output variables
are a matrix Q∈Cm×nwith orthonormal columns and a triangular matrix R∈Cn×n.
2. (a) Write a Matlab program that sets up a 15 ×40 matrix with entries 0 everywhere except
for the values 1 in the positions indicated in the picture below. The upper-leftmost 1 is in
position (2,2), and the lower-rightmost 1 is in position (13,39). This picture was produced
with the command spy(A).
0 5 10 15 20 25 30 35 40
0
5
10
15
(b) Call svd to compute the singular values of A, and print the results. Plot these numbers
using both plot and semilogy. What is the mathematically exact rank of A? How does
this show up in the computed singular values?
(c) For each ifrom 1 to rank(A), construct the rank-imatrix Bthat is the best approximation
to Ain the 2-norm. Use the command pcolor(B) with colormap(gray) to create images
of these various approximations.
3. (a) Write a Matlab function [W,R] = house(A) that computes an implicit representation of
a full QR factorization A=QR of an m×nmatrix Awith m≥nusing Householder
reflections. The output variables are a lower-triangular matrix W∈Cm×nwhose columns
are the vectors vkdefining the successive Householder reflections, and a triangular matrix
R∈Cn×n.
(b) Write a Matlab function Q = formQ(W) that takes the matrix Wproduced by house as
input and generates a corresponding m×morthogonal matrix Q.
4. Let Zbe the matrix
Z=
1 2 3
4 5 6
7 8 7
4 2 3
4 2 2
.
Compute the reduced QR factorization of Zin Matlab: by the Gram-Schmidt routine mgs
of Problem 1, by the Householder routines house and formQ of the previous problem, and
by Matlab’s built-in command [Q,R] = qr(Z,0). Compare these three and comment on any
differences you see.