Math 2270-2 Maple Project I Solutions to Part A > restart: with(linalg): Warning, the protected names norm and trace have been redefined and unprotected First, we define the two matrices. > A:=matrix(3,3,[1, 2, 3, 4, 5, 6, 7, 8, 9]); B:=matrix(3,3,[2, 1, 0, 1, 2, 1, 0, 1, 2]); 2 3 1 5 6 A := 4 8 9 7 1 0 2 2 1 B := 1 1 2 0 1a) Compute AB and BA. Are they the same? > AB:=evalm(A&*B); BA:=evalm(B&*A); 8 8 4 AB := 13 20 17 22 32 26 9 12 6 BA := 16 20 24 18 21 24 We see that the products are not the same. This indicates that matrix multiplication is noncommutative. 1b) Compute A+B and B+A. Are they the same? > C:=evalm(A+B); evalm(B+A); 3 3 3 7 C := 5 7 7 9 11 3 3 3 5 7 7 7 9 11 The two sums are equivalent, confirming that matrix addition is commutative. 1c) Define C to be A+B. Compute C^2 and compare it to A^2 + 2AB + B^2. Are they the same? Can you think of a small change you could make in the expression ‘‘A^2 + 2AB + B^2’’ in order to make it equal to C^2? Justify your answers! > C2:=evalm(C^2); AB2:=evalm(A^2+2*A&*B+B^2); 57 63 45 C2 := 99 127 141 143 183 205 56 59 43 AB2 := 96 127 134 147 194 207 From the computations above, we see that (A+B)(A+B) is not equal to AA+2AB+BB. Let’s look instead at the value of AA+AB+BA+BB. > evalm(A^2+A&*B+B&*A+B^2); 57 63 45 99 127 141 143 183 205 Here we see that (A+B)(A+B)=AA+AB+BA+BB. This follows since matrix multiplication is noncommutative, so, in general AB is not equal to BA. Therefore, when we distribute, we must be careful to keep the order of the matrices the same. 1d) Define v=(1,2,3) to be a vector. Compute Av. What does Maple give you when you try vA? > v:=vector([1, 2, 3]); Av:=evalm(A&*v); vA:=evalm(v&*A); v := [1, 2, 3 ] Av := [14, 32, 50 ] vA := [30, 36, 42 ] We see here that maple does not differentiate between column and row vectors. If we want to define the vector v to be a row vector or column vector, we should use the matrix definition. > vcol:=matrix(3,1,[1,2,3]); vrow:=matrix(1,3,[1,2,3]); 1 vcol := 2 3 vrow := [1 2 3] Now, we expect that only two products should be defined: (vrow A) and (A vcol). Let’s test this. > evalm(A&*vcol); 14 32 50 > evalm(vrow&*A); [30 36 42] > evalm(vcol&*A); evalm(A&*vrow); Error, (in linalg[multiply]) non matching dimensions for vector/matrix product Error, (in linalg[multiply]) non matching dimensions for vector/matrix product Notice that the last two calculations were not completed as the dimensions of the two matrices do not match up. Also, notice that the matrix-vector product Av is not equal to vA. This follows from the noncommutativity of matrix multiplication since a vector is just a special type of matrix with only one column or row. 1e) Solve Bx=v for x, where v is the vector in (1d). Get your solution all three ways that were indicated in the Maple Introductory Tutorial: by row-reducing the augmented matrix, by using the command ‘‘linsolve’’, and by using the inverse matrix to B. Row-Reduce the augmented matrix: > augBv:=augment(B,v); redBv:=rref(augBv); x:=col(redBv,4); 1 0 1 2 2 1 2 augBv := 1 1 2 3 0 1 1 0 0 2 1 0 0 redBv := 0 3 0 0 1 2 1 3 x := , 0, 2 2 Use the command "linsolve": > x:=linsolve(B,v); 1 3 x := , 0, 2 2 Use the inverse matrix to B: > Binv:=inverse(B); x:=evalm(Binv&*v); Binv := 3 4 -1 2 -1 2 1 1 4 -1 2 3 4 1 4 -1 2 1 3 x := , 0, 2 2 We get the same answer with all three methods. We can check our answer by verifying that multiplying B and x gives us v. > evalm(B&*x); [1, 2, 3 ] 2a) Solve Ax=v for x, where A and v are as indicated above. Verify, with Maple, that your solution x actually solves the equation Ax=v. > x:=linsolve(A,v); 1 2 x := − + _t1, − 2 _t1, _t1 3 3 We are given infinitely many solution vectors for the linear system. We can verify that the general solution solves the equation Ax=v by multiplying A by the general vector x. > evalm(A&*x); [1, 2, 3 ] 2b) Repeat your work above in order to solve Ax=w, where w=(-1,4,1). Explain your answer. > w:=vec([-1, 4, 1]); x:=linsolve(A,w); w := vec([-1, 4, 1 ]) x := Here, we are not able to get a vector x. This indicates that there may be no solution to the system Ax=w. To verify this, we can look at the reduced-row echelon form of the matrix A. > augAv:=augment(A,v): augAw:=augment(A,w): redAv:=rref(augAv); redAw:=rref(augAw); -1 1 0 -1 3 2 redAv := 1 2 0 3 0 0 0 0 1 redAw := 0 0 0 -1 1 2 0 0 0 0 1 From the computations above, we see that rref(A) has one row of zeros. Therefore, for any matrix b, the equation Ax=b either has no solutions (the system is inconsistent), or it has infinitely many solutions (the system is consistent). For the vector v, the system is consistent, x_3 is a non-leading variable and the system has infinitely many solutions. For the vector w, the system is inconsistent, so maple gives us an empty vector.