Numerical Linear Algebra Solutions Manual for Instructors Grégoire Allaire Sidi Mahmoud Kaber Contents 2 Exercises of chapter 2..................................... 3 3 Exercises of chapter 3..................................... 15 4 Exercises of chapter 4..................................... 21 5 Exercises of chapter 5..................................... 25 6 Exercises of chapter 6..................................... 35 7 Exercises of chapter 7..................................... 45 8 Exercises of chapter 8..................................... 51 9 Exercises of chapter 9..................................... 65 10 Exercises of chapter 10 ................................... 71 Preface This is the solution manual for the exercises of our book, \Numerical linear algebra". G.A., S.M.K. Paris,July 13, 2007. 2 Exercises of chapter 2 Solution of Exercise 2.3 The determinant of A is rigorously equal to e. However, when this number is very small, Matlab may (cid:12)nd a wrong value because of rounding errors.For instance with e=10(cid:0)20 we obtain >> e=1.e-20;n=5;p=NonsingularMat(n); >> A=p*diag([ones(n-1,1); e])*inv(p); >> det(A) ans = -1.5086e-14 Recall that the constant eps contains the (cid:13)oating point relative accuracy of Matlab >> eps ans = 2.2204e-16 Solution of Exercise 2.4 The rank is equal to 2. We note that the multi- plicationof Abyanonsingularmatrixdoesnotchangeitsrank.Assumethat A has size m n, and let C be a non singularmatrix of size m m. Since C (cid:2) (cid:2) is non singular, the vector spaces Im(A) and Im(CA) are in one-to-one cor- respondence and have thus the same dimension. Indeed, to each x Im(A), 2 we map Cx Im(CA) and to each x Im(CA), we map C(cid:0)1x Im(A). 2 2 2 Solution of Exercise 2.5 We build a matrix NR of size 2 10 containing (cid:2) di(cid:11)erent values of n and the rank of the correspondingmatrix A. 1. >> NR=[]; >> for n=1:10 >> A=rand(8,n)*rand(n,6);NR =[NR [n;rank(A)]]; >> end; >> NR NR = 1 2 3 4 5 6 7 8 9 10 4 CHAPTER 2. EXERCISES OF CHAPTER 2 1 2 3 4 5 6 6 6 6 6 We remark that the rank of A is equal to n for n 6, and equal to 6 for (cid:20) n 6. (cid:21) 2. With matrix BinChanceMat,we obtain >> NR NR = 1 2 3 4 5 6 7 8 9 10 1 2 3 4 4 5 6 6 6 6 This time around, we observe that the rank of A is always less than or equal to 6. 3. Let us showthat rk(AB) min(rk(A); rk(B)). Assume the dimensions (cid:20) of A and B are compatible for the product AB to make sense. Since Im(AB) Im(A), we have rk(AB) rk(A). Besides, according to the (cid:26) (cid:20) rank theorem dim KerB+ rkB = dim Ker(AB)+ rk(AB): Since Ker(B) Ker(AB), we have the upper bound rk(AB) rk(B), (cid:26) (cid:20) thereby proving the result. Matricesm nde(cid:12)nedbyfunctionrandhaveagreatprobabilityofbeing (cid:2) of maximal rank, that is, of rank equal to min(m;n). With the random function BinChanceMat, this probability is smaller, which explains the observed results. Solution of Exercise 2.6 Finding the rank of n u ut. i=1 i i 1. Case when A is de(cid:12)ned using the function raPnd. Using the following in- structions >> n=5;A=zeros(n,n);r=5; >> for i=1:r u=rand(n,1);A=A+u*u’; end; >> rank(A) ans = 5 we \almost always"obtain that the rank of A is equal to r. 2. Case when A is de(cid:12)ned using the function BinChanceMat.Using the fol- lowing instructions >> A=zeros(n,n); >> for i=1:r u=BinChanceMat(n,1);A=A+u*u’; end; rank(A) ans = 4 5 we merely obtain that the rank of A is less than or equal to r. 3. Explanation. For any x Rn, we have 2 r r Ax= (u ut)x= x;u u : i i h ii i i=1 i=1 X X So the vectorsu span the imageof A and, consequently,the rankof A is i alwayslessthan orequal tor. If thesevectorsarelinearlyindependent in Rn (whichisverylikelywithrandandmoreunlikelywithBinChanceMat), then they form a basis of the image of A. The dimension of this space is therefore r. Solution of Exercise 2.8 1. >> A=[1:3;4:6;7:9;10:12]; det(A’*A) ans = 0 >> B=[-1 2 3;4:6;7:9;10:12]; det(B’*B) ans = 216 We remark that the matrix AtA is singular, while BtB is not. 2. The rank of A is equal to 2 and the rank of B is equal to 3. 3. Let X be a matrix of size m n, with m n. The rank theorem implies (cid:2) (cid:21) that dim KerX+ rkX =n. The following alternative holds true: eithertherankofX ismaximal,thatis,equalton,whichisequivalent (cid:15) to say that X is injective (KerX = 0 ) and thus the square matrix f g X(cid:3)X is also injective, hence non singular since X(cid:3)Xx=0= 0= X(cid:3)Xx;x = Xx 2 = Xx=0= x=0; ) h i k k ) ) or rk(X) < n and thus X is not injective, and neither is the square (cid:15) matrix X(cid:3)X. 4. This time, both matricesAAt and BBt aresingular.Indeed, foramatrix X of size m n, with m < n, even if its rank is maximal, that is, equal (cid:2) to m, we have dim KerX = n m and X is never injective. Thus the (cid:0) square matrix X(cid:3)X is always singular. Solution of Exercise 2.9 Rank of A+uut. >> A=MatRank(20,20,17); Q=null(A’); >> size(Q) ans = 20 3 >> u=Q(:,2); rank(A+u*u’) ans = 18 6 CHAPTER 2. EXERCISES OF CHAPTER 2 We notice that the rank of the matrix A+uut is equal to r+1. Indeed for any x Rn, we have 2 (A+uut)x=Ax+uutx=Ax+ x;u u; h i and since u Ker(At) =(ImA)?, x;u u is orthogonal to ImA and there- 2 h i fore the dimension of Im(A+uut) is equal to r+1. Solution of Exercise 2.13 The function triu returns the upper triangu- lar part of a matrix. Similarly, the lower triangular part is obtained by the function tril. >> n=5;A=rand(n,n);A=triu(A)-diag(diag(A)) A = 0 0.1942 0.0856 0.7285 0.2183 0 0 0.9793 0.2508 0.9558 0 0 0 0.1685 0.4082 0 0 0 0 0.6033 0 0 0 0 0 To get the successive powers of A, we use the variable ans as follows. >> A*A ans = 0 0 0.1902 0.0631 0.6601 0 0 0 0.1650 0.5511 0 0 0 0 0.1017 0 0 0 0 0 0 0 0 0 0 >> ans*A ans = 0 0 0 0.0320 0.1157 0 0 0 0 0.0996 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 We see that An is equal to the zero matrix. Such a matrix is said to be nilpotent.Explanation:sincealltheeigenvaluesofAarezero,itscharacteristic polynomial is p (x) = ( 1)nxn and by the Cayley{Hamilton theorem, we A (cid:0) have indeed p (A)=0. A Solution of Exercise 2.14 We give the results for m=n=6. 1. >> H=hilb(6);eig(H) ans = 0.0000 0.0000