linalg1.mws

Linear Algebra with Maple

First we load the "linalg" package:

> with(linalg):

Warning, new definition for norm

Warning, new definition for trace

Ignore the warning statements. Notice the line above ended in ":" rather than ";". Change this and see what happens.

We shall now define some martices 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]])

> evalm(A &* b);

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

> evalm(A &* b + 4*b);

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

> evalm(A &* A - 3*transpose(A));

MATRIX([[12, 27, 12], [12, 24, 6], [0, 9, 0]])

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

> Ab:=augment(A,b);

>

Ab := MATRIX([[3, 4, 2, 1], [3, 5, 1, 2], [0, 2, 1,...

Next we put it into reduced row echelon form.

> rref(Ab);

MATRIX([[1, 0, 0, 1/3], [0, 1, 0, 1/3], [0, 0, 1, -...

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

> linsolve(A,b);

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

Let's try another one.

> A:=matrix([[1,2,0,1],[0,-1,3,1],[1,1,3,2],[1,1,1,1]]);

A := MATRIX([[1, 2, 0, 1], [0, -1, 3, 1], [1, 1, 3,...

> b:=matrix([[1],[2],[3],[1]]);

b := MATRIX([[1], [2], [3], [1]])

> rref(augment(A,b));

MATRIX([[1, 0, 0, 0, -1], [0, 1, 0, 1/2, 1], [0, 0,...

Write out the solutions in vector form. Compare with the output of linsolve. If you want the answer in decimal form use evalf(rref(augment(A,b)));.

Homework Problem: Solve the three martix equations below using rref. Write the solution in vector form. You can check your work with linsove.

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

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

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

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