11.7. THE SINGULAR VALUE DECOMPOSITION∗ 207

11.6.5 Using MATLABYou may notice that the Gram Schmidt process is pretty tedious but routine. Therefore, itis not surprising that it can be automated using MATLAB. One way to do it would be touse what is known as the QR factorization. Given a real m×n matrix A which has linearlyindependent columns, you can always write it in the form A =QR where Q is an orthogonalmatrix and R is an upper triangular matrix in the sense that all entries are 0 below the maindiagonal. Actually, the computer algebra system doesn’t use the Gram Schmidt process. Ituses something called Householder reflections, but one obtains the same essentials althoughsometimes a different set of vectors, the columns of Q being an orthonormal set. The spanof these columns will coincide with the span of the columns of A and in fact, the span ofthe first k columns of A will be the span of the first k columns of Q just as in the GramSchmidt process. Here is the syntax:

>>A=[1,2,3;4,2,1;2,6,7;1,-4,2];[Q,R]=qr(A)Then press enter and you get the following.

Q=-0.2132 0.1756 -0.2593 0.9255-0.8528 -0.1892 0.4862 -0.0244-0.4264 0.6485 -0.5139 -0.3653-0.2132 -0.7161 -0.6575 -0.0974

R=-4.6904 -3.8376 -4.90360 6.7285 3.44530 0 -5.20430 0 0

If you want to see something horrible, replace qr(A) with qr(sym(A)). This way it givesthe exact values. You can check your work by >>Q*Q’ and press enter. The Q’ means theconjugate transpose in MATLAB. Since everything is real here, this is just the transpose.

There is so much more that could be discussed about the QR factorization, but this willsuffice here.

As to plotting data with a curve as in the least squares example, use the followingsyntax.

x=-1:.1:5;y=1.11*x+1.146;plot(x,y,0,1,’*’,2,3,’*’,2,4,’*’,3,4,’*’,3,5,’*’,4,6,’*’,4,5,’*’)

In MATLAB, you press shift enter to get to a new line and you press enter to get it todo something.

11.7 The Singular Value Decomposition∗

In this section, A will be an m×n matrix. To begin with, here is a simple lemma.

Lemma 11.7.1 Let A be an m× n matrix. Then A∗A is Hermitian and all its eigenvaluesare nonnegative.

Proof:It is obvious that A∗A is Hermitian because (A∗A)∗ = A∗ (A∗)∗ = A∗A. SupposeA∗Ax= λx. Then

λ |x|2 = (λx,x) = (A∗Ax,x) = (Ax,Ax)≥ 0. ■

Definition 11.7.2 Let A be an m×n matrix. The singular values of A are the square rootsof the positive eigenvalues of A∗A.