% Math 340 matlab #1 answers. All comments preceeded by %, % other lines are matlab output. % many of you omitted the following % and hence got the same matrices as one another. >> rand('state',sum(100*clock)); % Problem #1 >> A = rand(5,7) A = 0.5333 0.6321 0.9183 0.7837 0.9959 0.5705 0.0734 0.4452 0.5166 0.9458 0.9808 0.4561 0.6714 0.2466 0.7185 0.6079 0.0675 0.8115 0.7617 0.0960 0.0100 0.7573 0.7400 0.6021 0.0784 0.6598 0.9522 0.4460 0.9915 0.0771 0.1647 0.0286 0.2146 0.3971 0.1054 >> rref(A) ans = 1.0000 0 0 0 0 0.3367 0.1347 0 1.0000 0 0 0 0.8513 0.8081 0 0 1.0000 0 0 0.7393 0.2326 0 0 0 1.0000 0 -0.3845 -0.1926 0 0 0 0 1.0000 -0.5269 -0.5743 % The columns of A are linearly dependent because there is not a pivot in % every column. (See example 2, page 80 of Cullen). % For example if Ai represents the ith column of A, then % .3367*A1 + .8513*A2 + .7393*A3 -.3845*A4 -.5269*A5 -A6 = 0 % is a nontrivial linear combination of the columns which equals 0. % The Span of the columns of A is all of R_{5x1}, all 5x1 matrices. % See the top of page 77 of Cullen. Since there is a pivot in every row % we know that AX = K always has a solution. Hence the span of the % columns of A is all 5x1 matrices. % Many of you said some nonsense here. Some of you were talking about % the span of A. Technically, the span of A is the line {cA | c is in F} % in R_{5x7}. Remember, the span of any bunch of vectors is a subspace. %---------------- % Problem 2 >> U = rand(7,1) U = 0.5897 0.2038 0.2324 0.6113 0.6822 0.9422 0.2137 >> K = A*U K = 2.3683 2.1836 1.6714 2.2278 1.1992 >> X = A\K X = 0.9357 1.1785 0.9786 0.2079 0.0630 0 0 % Note that X is not equal to U even though they are both % solutions to AX=K. This is not suprising since AX=K has infinitely % many solutions. So it is unlikely that matlab will find the % solution U, it will probably find another solution. % Using thm 1.15 on page 41 of Cullen and part 1 we see that all solutions are % % U + x6 [ -.3367; -.8513; -.7393; .3845; .5269; 1; 0] + % + x7 [ -.1347; -.8081; -.2326; .1926; .5743; 0; 1] % where we can let x6 and x7 be any scalars. % % Some of you gave all solutions as {(sU+tX)/(s+t)}. % These are solutions, but do not list all solutions. % they form a line (not through the origin) in R_{7x1} % but the set of all solutions form a plane (not through the origin). % % Some others said that sU+tX will be a solution, but this is not true unless % s+t=1. Note that A(sU+tX) = sAU+tAX = sK+tK = (s+t)K. %------------ % Problem 3 >> A = rand(4,4), B=rand(4,4) A = 0.4472 0.0996 0.3375 0.1361 0.4685 0.0849 0.8520 0.9609 0.1034 0.8616 0.0032 0.9900 0.3962 0.2898 0.4125 0.4117 B = 0.5686 0.6420 0.1770 0.3184 0.0661 0.9103 0.8561 0.9403 0.3372 0.7124 0.8769 0.6180 0.3602 0.3072 0.1126 0.1806 >> rref(A), rref(B) ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 % because the rref af A and B is the identity we know they are both nonsingular. % their columns are linearly independent by for example by thm 2.14 p 90 % of Cullen or the test used in problem #1, that every column has a pivot. % If you did this 100 times you would still expect linearly independent % columns. This is because, say, the determinent is some random number % and hence unlikely to be 0, so the matrix will be nonsingular. % Some of you did matrices with integer entries, say from 1 to 10. % while it is still unlikely that such a matrix is singular, it is more likely % since there are fewer possibilities for the determinent. % the chance is at least 1/240000, probably a bit more. % If you did 4x4 matrices with entries just 0 and 1, you could expect a % couple of singular matrices in 100 tries, I think. % The span of the columns of A is all R_{4x1} since there is a pivot in each row. %-------------- % Problem #4 >> det(A), det(B), det(A*B), det(inv(A)*B') ans = 0.0302 ans = 0.0147 ans = 4.4447e-04 ans = 0.4888 >> det(A*B)-det(A)*det(B) ans = 1.6805e-18 % Note that det(AB) and det(A)det(B) are extremely close to one another. % the small difference 1.68 * 10^{-18} is due to roundoff error. >> det(inv(A)*B')-det(B)/det(A) ans = 1.4433e-15 % We expect det(inv(A)*B') = det(inv(A))*det(B') = (1/det(A))det(B). % and indeed they are very close, with the small difference % due to roundoff error. The rounoff error is a bit higher here than % in the previous part because more operations are needed to compute inv(A). % I took off a couple points for % not finding the simplest expression det(B)/det(A) on this one. %------- % Problem 5 % So many of you misinterpereted what I meant by not printing out % the matrices Ai. Many didn't print out anything at all. % What I meant was to not actually print out the Ai, but to included % all relevant natlab output. % Anyway i ended up being generous here. >> A1=(A'*B')'; A2=(B'*A')'; A3=B*A; A4=A*B; >> max(max(abs(A1-A2))), max(max(abs(A1-A3))), max(max(abs(A2-A4))) ans = 1.1892 ans = 0 ans = 0 % So we see that A1=A3 and A2=A4, but A1 and A3 are not equal to A2 and A4. >> A1=inv(A)*inv(B); A2=inv(B)*inv(A); A3=inv(B*A); A4=inv(A*B); >> max(max(abs(A1-A2))), max(max(abs(A1-A3))), max(max(abs(A2-A4))) ans = 82.9546 ans = 1.6769e-12 ans = 4.9738e-14 % So we see that A1 and A3 are close to being equal (just a tiny bit of % roundoff error) and A2 and A4 are also essentially equal, % but A1 and A3 are not equal to A2 and A4.