Linear Algebra with Maple

First we load the "LinearAlgebra" package:

> with(LinearAlgebra):

Notice the line above ended in ":" rather than ";". Change this and see what happens. You should get a list of all the comands in the LinearAlgebra package.

We shall now define some matrices and do simple manipulations.

> A:=Matrix([[3, 4, 2],[3, 5, 1],[0,2,1]]);

A := Matrix([[3, 4, 2], [3, 5, 1], [0, 2, 1]])

> b:=Matrix([[1],[2],[0]]);

b := Matrix([[1], [2], [0]])

Matrix multiplication:

> A.b;

Matrix([[11], [13], [4]])

Matrix multiplication, addition and scalar multiplication.

> A.b + b.4;

Matrix([[15], [21], [4]])

For some reason scalar multiplication has to have the scalar on the right.

> 4.b;

Error, missing operator or `;`

Powers and transpose.

> A^2 - Transpose(A);

Matrix([[18, 33, 12], [20, 34, 10], [4, 11, 2]])

Matrix inverse.

> A^(-1);

Matrix([[1/3, 0, (-2)/3], [(-1)/3, 1/3, 1/3], [2/3, (-2)/3, 1/3]])

The determinant.

> Determinant(A);

9

Now let's work on solving systems of equations. Suppose Ax=b. We set up the augmented matrix.

> Ab:=Matrix([A,b]);

Ab := Matrix([[3, 4, 2, 1], [3, 5, 1, 2], [0, 2, 1, 0]])

Next we put it into reduced row echelon form.

> ReducedRowEchelonForm(Ab);

Matrix([[1, 0, 0, 1/3], [0, 1, 0, 1/3], [0, 0, 1, (-2)/3]])

The solution is x=1/3, y=1/3, z=-2/3. Here is a one step method:

> LinearSolve(A,b);

Matrix([[1/3], [1/3], [(-2)/3]])

Let's try another one.

> B:=Matrix([[1,2,0,1],[0,-1,3,1],[1,1,3,2],[1,1,1,1]]);

B := Matrix([[1, 2, 0, 1], [0, -1, 3, 1], [1, 1, 3, 2], [1, 1, 1, 1]])

> c:=Matrix([[1],[2],[3],[1]]);

c := Matrix([[1], [2], [3], [1]])

> ReducedRowEchelonForm(Matrix([B,c]));

Matrix([[1, 0, 0, 0, -1], [0, 1, 0, 1/2, 1], [0, 0, 1, 1/2, 1], [0, 0, 0, 0, 0]])

Write out the solutions in vector form. Compare with the output of LinearSolve below.

> LinearSolve(B,c);

Matrix([[-1], [1-1/2*_t0[1, 1]], [1-1/2*_t0[1, 1]], [_t0[1, 1]]])

The symbol _t0[1, 1] is generated by Maple to be the free parameter. The solution set is (w,x,y,z)=(-1,1,1,0) + (0,-1/2,-1/2,1)t for all real values of t.

Practice Problems: Solve the three matrix equations below using ReduceRowEchelonForm. Write the solution set in vector form. You can check your work with LinearSolve. Let

A := MATRIX([[1, -2, 1, -1], [2, -3, 2, -3], [3, -5, 3, -4], [-1, 1, -1, 2]])                 a := MATRIX([[4], [-1], [3], [5]])

B := MATRIX([[1, -3, 1, 2], [1, -1, 2, 4], [2, -8, -1, 0], [3, -9, 4, 0]])                        b := MATRIX([[8], [17], [-8], [33]])

C := MATRIX([[0, 0, 1, 2, -1, 4], [0, 0, 0, 1, -1, 3], [2, 4, -1, 3, 2, -1]])        c := MATRIX([[5], [0], [1]])

Solve Ax=a, Bx=b and Cx=c.