Linear Algebra Powertool
Solving Matrix Equations
On Line Section 1.5
Worksheet by Michael K. May S.J., revised by Russell Blyth
> restart: with(linalg): with(plots): with(plottools):
Warning, the protected names norm and trace have been redefined and unprotected
Warning, the name changecoords has been redefined
Warning, the name arrow has been redefined
Outline
This worksheet covers material parallel to the On Line 1.5 section.
The basic objectives are:
Part1: Multiplying a matrix and a vector
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]);
Now we want to compute the product. Maple uses &* as the symbol for the noncommutative product of matrices. The command evalm is used to evaluate matrix expressions.
> B:= evalm(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.
> evalm(col(A,1)*X[1]+col(A,2)*X[2]+col(A,3)*X[3]+col(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.
> evalm(X&*A);
Error, (in linalg[multiply]) non matching dimensions for vector/matrix product
Sometimes we want to put two matrices (or a matrix and a vector) together into a larger matrix. The command augment puts matrices together one to the right of the other, while the command stack puts them together one below the other.
>
augment(A,B);
stackmatrix(A,X);
[Version warning: In Maple V R4 the command is stack rather than stackmatrix.]
Exercises:
1) Use the commands randmatrix and randvector 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.
>
Part2: Solving a matrix-vector equation
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 := augment(A,B);
C1a := gausselim(C1);
gensol1 := backsub(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.
> subs(_t[1]=4,op(gensol1));
A slight variation of the method above is to perform Gauss-Jordan elimination before back substitution.
>
C1b := gaussjord(C1);
gensol2 := backsub(C1b);
A third option is to use the linsolve command that we saw in the previous worksheet.
> gensol3 := linsolve(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);
Exercises:
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.
>
Part 3: An extended exercise
For these exercises we will work with a fixed matrix A and a fixed vector B
Let A =
and B =
.
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.
>
>