% John Doe % 1234 % Section C2 % Math 250 MATLAB Lab Demo rand('seed', 1234) % Question 1(a) A = [0 1 2; 3 4 5] A = 0 1 2 3 4 5 a = [9 ; -1] a = 9 -1 A A = 0 1 2 3 4 5 a a = 9 -1 whos Name Size Bytes Class Attributes A 2x3 48 double a 2x1 16 double % Question 1(b) a12 = A(1,2) a12 = 1 % The entry in the first row and second column of A is indeed 1. % Question 1(c) A A = 0 1 2 3 4 5 % The matrix A is not a diagonal matrix, because it is not a square matrix. %Question 1(d) D = rdiag(3) D = 9 0 0 0 2 0 0 0 3 % The matrix D is indeed a diagonal matrix, since it is a square matrix % of size 3x3, and the entries D(1,2), D(1,3), D(2,3), D(2,1), % D(3,1), and D(3,2) are all 0. 23*D ans = 207 0 0 0 46 0 0 0 69 % 23*D is a diagonal matrix. 0*D ans = 0 0 0 0 0 0 0 0 0 % 0*D is a diagonal matrix. -17*D ans = -153 0 0 0 -34 0 0 0 -51 % -17*D is a diagonal matrix. (1/10)*D ans = 0.9000 0 0 0 0.2000 0 0 0 0.3000 % (1/10)*D is a diagonal matrix. % Question 1(e) % If B is a diagonal matrix, then whenever i is different from j, % B(i,j)=0. Let c be a scalar. To see that cB is a diagonal matrix, % we must check that cB(i,j) = 0 whenever i is different from j. The % (i,j) entry of cB is given by c*B(i,j). Hence if i is different from % j, cB(i,j) = c*B(i,j) = c*0 = 0. Therefore c*B is also a diagonal % matrix.