# MA 305 Spring 2K Homework 5 Solutions > read("/afs/eos.ncsu.edu/users/k/kaltofen/www/courses/LinAlgebra/Maple/ > initlib.mpl"): > with(refpkg): > with(lsqpkg): > with(linalg): Warning, new definition for norm Warning, new definition for trace # Problem 1 # (a.) # The vector space W; is the column space of the matrix A := matrix([[1, # 2], [1, -1], [1, 1]]);, so the orthogonal complement of W is the null # space of the transpose of A;. Thus, we can use the nullspace command # to find the basis for the orthogonal complement of W. > A := matrix(3,2,[1,2,1,-1,1,1]); [1 2] [ ] A := [1 -1] [ ] [1 1] > nullspace(transpose(A)); {[2, 1, -3]} # Thus, a basis for the orthogonal complement of W is the one vector # (2,1,-3). # (b.) # We know the basis of W is made of two three-dimensional vectors, so W # is a plane through the origin in three-space. Thus, we know the # orhtogonal complement of W, which is the space of all vectors in # three-space that are orthogonal to everything in W, is a line through # to origin in three-space. # # Alternatively, we have computed a basis for the orthogonal complement # of W to be one three-dimensional vector, so again we see it is a line # through the origin in three-space. # Problem 2 > A := matrix(3,4,[1,3,1,2,1,4,1,1,2,1,2,1]); [1 3 1 2] [ ] A := [1 4 1 1] [ ] [2 1 2 1] # (a.) # We can find a basis for A; by computing which columns of A; are # linearly independent. To do this, we can find the row echelon form of # A; and see which columns have pivots in them. > ref(A); [1 3 1 2] [ ] [0 1 0 -1] [ ] [0 0 0 -8] # We see the REF of A; has pivots in the first, second, and fourth # columns, so we know the first, second, and fourth columns of A; form a # basis for the column space of A;. Thus, a basis for the column space # of A; is the three vectors (1,1,2), (3,4,1), and (2,1,1). # # Alternatively, we could use linalg's colspace command to compute a # basis. > colspace(A); {[1, 0, 0], [0, 1, 0], [0, 0, 1]} # Thus we know another basis for the column space of A; is the three # vectors (1,0,0), (0,1,0), and (0,0,1). # (b.) # We can find a basis for the row space of A; by computing which rows of # A; are linearly independent. Because the rows of A; are just the # columns of A^T;, we can use the row echelon form of A^T; to do this. > ref(transpose(A)); [1 1 2] [ ] [0 1 -5] [ ] [0 0 -8] [ ] [0 0 0] # We see the REF of A^T; has a pivot in every column, so we know all # three rows of A; are linearly independent. Thus a basis for the row # space of A; is the three vectors (1,3,1,2), (1,4,1,1), and (2,1,2,1). # # Alternatively, we could use linalg's rowspace command. > rowspace(A); {[0, 0, 0, 1], [1, 0, 1, 0], [0, 1, 0, 0]} # So another basis for the row space of A; is the three vectors # (0,0,0,1), (1,0,1,0), and (0,1,0,0). # (c.) # The rank of a matrix was defined in class to be the number of pivot # elements in its row echelon form. Alternative definitions are the # dimensions of the column and row spaces of the matrix. Using any of # these definitions, we see the rank of the matrix A; is 3. Similarly, # linalg's rank command gives the same answer. > rank(A); 3 # Problem 3 > u := vector([1,2,1]); u := [1, 2, 1] > v := vector([-1,3,2]); v := [-1, 3, 2] # (a.) > innerprod(u,v); 7 # (b.) > norm(u-v,2); sqrt(6) # (c.) # EIther of these two methods will give the angle between the two # vectors. > angle(u,v); arccos(1/12 sqrt(6) sqrt(14)) > arccos(innerprod(u,v)/(norm(u,2)*norm(v,2))); arccos(1/12 sqrt(6) sqrt(14)) # (d.) > innerprod(u,v)/innerprod(v,v) * v; 1/2 v > evalm(%); [-1/2, 3/2, 1] # Problem 4 # (a.) # We look at the equation a*x^2+b*y+c = z; and we see this can be # written in the matrix form A*x = b; where the vector x := vector([a, # b, c]);, the matrix A; has three columns: the first corresponding to # the square of the x; coordinates, the second corresponds to the y; # coordinates, and the thid is all ones. Finally, the vector b; is the # z; coordinates. > > x_coords := [0,1,-1,1,-1]; x_coords := [0, 1, -1, 1, -1] > x_coords_sqrd := [0,1,1,1,1]; x_coords_sqrd := [0, 1, 1, 1, 1] > y_coords := [0,1,2,-1,1]; y_coords := [0, 1, 2, -1, 1] > ones := [seq(1,i=1..5)]; ones := [1, 1, 1, 1, 1] > z_coords := [2+1/10, 7-2/10, 11-1/10, -1+2/10, 7-1/10]; 21 109 69 z_coords := [--, 34/5, ---, -4/5, --] 10 10 10 > A := blockmatrix(1,3,[x_coords_sqrd,y_coords,ones]); [0 0 1] [ ] [1 1 1] [ ] A := [1 2 1] [ ] [1 -1 1] [ ] [1 1 1] > b := vector(z_coords); [21 109 69] b := [--, 34/5, ---, -4/5, --] [10 10 10] # Now, this vector b; is not in the column space of A;, so the system is # inconsistant. What we really want to do is to solve the system # A*x_prime = b_prime;, where b_prime; is the orthogonal projection of # b; onto the column space of A;. # # However, if we multiply both sides of the matrix equation by the # transpose of A, we get a system that we can solve. This system, # A^T*A*x = A^T*b; is the normal equation, and its solution is exactly # x_prime;. > x := linsolve(evalm(transpose(A)&*A),evalm(transpose(A)&*b)); [89 369 21] x := [--, ---, --] [95 95 10] # Thus, we see the constants are a = 89/95;, b = 369/95;, and c = # 21/10;. # # Alternatively, we could have used the fit command from Maple's stats # package. > model := stats[fit,leastsquare[[x,y,z],z=a*x^2+b*y+c, > {a,b,c}]]([x_coords, y_coords,z_coords]); 89 2 369 21 model := z = -- x + --- y + -- 95 95 10 # Notice, this gives us the same answers for the constants. # # To estimate z;, we use the constants we found, plus the values of x = # 5; and y = 10; and the original equation: > 89/95*5^2 + 369/95*10 + 21/10; 12229 ----- 190 # Alternatively, we could evaluate the model from the fit command at the # appropraite x; and y;. > subs({x=5,y=10},model); 12229 z = ----- 190 # (b.) # The solution from the normal equations is exactly x_prime;, so the # system is given by the matrix > print(A); [0 0 1] [ ] [1 1 1] [ ] [1 2 1] [ ] [1 -1 1] [ ] [1 1 1] # times the vector > print(x); [89 369 21] [--, ---, --] [95 95 10] # equals the vector > evalm(A&*x); [21 263 2053 -161 263] [--, ---, ----, ----, ---] [10 38 190 190 38 ] # (c.) > norm(evalm(A&*x)-b,2); 1/38 sqrt(38) # Problem 5 # (a.) # This is an inner product. To see this, we must show it satisifies the # three axioms given in class. # IP1 > anglebracket(x,x) = 5*x[1]^2+x[2]^2;# which we see is zero if x is # the zero vector and is positive otherwise, and thus the first axiom is # satisfied. # IP2 > anglebracket(x,y) = 5*x[1]*y[1]+x[2]*y[2];# and anglebracket(y,x) = # 5*y[1]*x[1]+y[2]*x[2];. Because multiplication of real numbers is # commutative, we see this are equal, and thus the second axiom is # satisfied. # IP3 > anglebracket(alpha*x+beta*y,z) = > 5*(alpha*x[1]+beta*y[1])*z[1]+(alpha*x[1]+beta*y[2])*z[2];# and # alpha*anglebracket(x,z)+beta*anglebracket(y,z) = # alpha*(5*x[1]*z[1]+x[2]*z[2])+beta*(5*y[1]*z[1]+y[2]*z[2]);. Because # multiplication of real numbers is commutative, this are equal, and # thus the third axiom is satisfied. # All three axioms are satisfied, so this is an inner product and it's # corresponding norm is sqrt(anglebracket(x,x)) = # sqrt(5*x[1]^2+x[2]^2);. # (b.) # This is not an inner product because the first axiom, IP1, does not # hold. For example, let x = (0, 1);. Then, anglebracket(x,x) = -1;. # (c.) # This is not an inner product because the first axiom, IP1, does not # hold. For example, let x = (0, 0, 1);. Then, anglebracket(x,x) = 0;, # but x; is not the zero vector. # (d.) # This is not an inner product because the first axiom, IP1, does not # hold. For example, let f(x) = x;. Then, anglebracket(f,f) = 0;, but # f; is not the zero polynomial. # Problem 6 # There are two ways to do this problem. One way is to use the lsqpkg # package and its gram_schmidt function. This function takes a matrix # and returns an orthogonal basis for the column space. To use it, we # would make a matrix whose columns are the given vectors. > v[1] := vector([1,1,2]); v[1] := [1, 1, 2] > v[2] := vector([2,1,0]); v[2] := [2, 1, 0] > v[3] := vector([0,0,1]); v[3] := [0, 0, 1] > A := blockmatrix(1,3,[seq(v[i],i=1..3)]); [1 2 0] [ ] A := [1 1 0] [ ] [2 0 1] > gram_schmidt(A); [1 3/2 2/21] [ ] [ -4 ] [1 1/2 -- ] [ 21 ] [ ] [2 -1 1/21] # Thus, orthogonal vectors would be (1,1,2), (3/2;,1/2;,-1;), and # (2/21;,-4/21;,1/21;). # # Another method would be to use linalg's GramSchmidt function with # takes a list of vectors. > GramSchmidt([seq(v[i],i=1..3)]); -4 [[1, 1, 2], [3/2, 1/2, -1], [2/21, --, 1/21]] 21 # Notice, this returns the same three vectors. #