Solving Matrix EquationsWorksheet by Michael K. May S.J., revised by Russell Blythwith(LinearAlgebra):
<Text-field layout="Heading 1" style="Heading 1">Outline:</Text-field>The basic objectives are:1) Learn to use Maple to multiply matrices and vectors.2) Learn to use Maple to solve Matrix-vector equations.3) To complete an extended exercise.
<Text-field layout="Heading 1" style="Heading 1">Part 1: Multiplying a matrix and a vector</Text-field>We want to change our point of view. So far we have been focused on solving systems of linear equations and have manipulated matrices to perform that task. In this section we consider the equivalent matrix equation and how to solve it directly. Before we can talk about solving matrix equations we need to be able to multiply a matrix and an appropriately sized vector. We start by defining a matrix A and a vector X of appropriate size so that the product AX is defined. (The product AX of an m by n matrix A with the vector X is only defined if X is an n-vector.)A := Matrix(3,4,[[1, 2, 1, 3], [-5, 7, 2, 2],[ 13, 4, 4, 3]]); X := Vector(4, [1, 3, -2, 4]);Recall that we can create the same matrix and vector using the angle bracket constructor.A1 := <<1, -5, 13> | <2, 7, 4> | <1, 2, 4> | <3, 2, 3>>; X1 := <1, 3, -2, 4>;Now we want to compute the product. Maple uses . as the symbol for the noncommutative product of matrices. B := A.X;Maple also lets you use commands for the operations. The command to multiply a matrix followed by a vector is MatrixVectorMultiply. There are similar commands for a vector and a matrix as well as for the product of two matrices.MatrixVectorMultiply(A,X);Recall that the product AX can be thought of as a linear combination of the columns of A with the scalars used being the entries of X. If we compute this linear combination, we should get the same result.Column(A,1)*X[1]+Column(A,2)*X[2]+Column(A,3)*X[3]+Column(A,4)*X[4];Note that multiplication of a matrix by a vector is not commutative. In fact in our case, X.A is not even defined.X.A;VectorMatrixMultiply(X,A);Sometimes we want to put two matrices (or a matrix and a vector) together into a larger matrix. We can do this with the angle bracket constructor, using a comma to put matrices on top of each other and a vertical bar to put them next to each other.<A|B>; <A,Transpose(X)>;
<Text-field layout="Heading 2" style="Heading 2">Exercises:</Text-field> 1) Use the commands RandomMatrix and RandomVector to create a random 4 by 5 matrix named Mat1 and a 5-vector named Vec1. Compute the product Mat1 . Vec1, assigned to a 4-vector named Vec2. 2) Augment Mat1 by Vec2 to create a 4 by 6 matrix. (Read carefully:) Stack Vec1 on top of Mat1 to create a 5 by 5 matrix.
<Text-field layout="Heading 1" style="Heading 1">Part 2: Solving a matrix-vector equation</Text-field>Having computed B = AX, we want to shift the focus: given the matrix A and the vector B, solve for X in the matrix equation AX = B.The first method is to make an augmented matrix from A and B, then use Gaussian elimination to produce a matrix in echelon form. We then use back substitution to find the general solution to the matrix equation.C1 := <A|B>; C1a := GaussianElimination(C1); gensol1 := BackwardSubstitute(C1a);Here _t[1] is a parameter that can take any value. To get back to our original X, we need to set _t[1] equal to 4.eval(gensol1,_t[1]=4);A slight variation of the method above is to perform Gauss-Jordan elimination before back substitution.C1b := ReducedRowEchelonForm(C1); gensol2 := BackwardSubstitute(C1b);A third option is to use the linsolve command that we saw in the previous worksheet.gensol3 := LinearSolve(A,B);A fourth method notes that the general solution to the equation AX = B is any vector of the form tv+nv, where tv is a particular solution to the equation (a translation vector), and nv is any vector in the null space of A. The Maple command nullspace(A) returns a basis for the nullspace of A. (A basis of a vector space is a spanning set of minimal size.)NullSpace(A);
<Text-field layout="Heading 2" style="Heading 2">Exercises:</Text-field> 3) Find a basis of the null space of the matrix Mat1 you created above. 4) Solve the matrix-vector equation (Mat1)(X) = Vec2 by reducing an augmented matrix.5) Solve the matrix-vector equation (Mat1)(X) = Vec2 by using the linsolve command.
<Text-field layout="Heading 1" style="Heading 1">Part 3: An Extended exercise:</Text-field>For these exercises we will work with a fixed matrix A and a fixed vector B.Let A = NiMtJSdtYXRyaXhHNiM3JjcoIiM8LCQiIichIiIiIzgiI0YiI2siIz43KCIiJUYpLCQiI0xGKyIjRCIiKCIiKjcoIiNiLCQiI0NGK0YqIiQxIiIkKj4iI203KCIjKiksJCIjT0YrIiNLIiRnIiIkRiQiJC8i and B = NiMtJSdtYXRyaXhHNiM3JjcjIiM8NyMiIiU3IyIjYjcjIiMqKQ==.Exercises: 6) Compute the rank of A and determine the number of free variables in the system AX = 0. Find a basis for the nullspace of A. (Name the vectors of your basis W1, W2, ...) How could you have predicted the size of the basis? By inspection, find a vector X0 such that (A)(X0)=B. Show that any vector of the form X0 + a1*W1 + a2*W2 + ... is a solution to the equation AX = B.