Sec1-2-GaussElim.mws

Linear Algebra Powertool

Solving a system by Gaussian Elimination

Worksheet by Russell Blyth

Start linear algebra computations by loading the linalg package:

> with(linalg);

Warning, the protected names norm and trace have been redefined and unprotected

[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...

Enter the augmented matrix of the system.

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

A := matrix([[-1, 1, -1, -8], [1, 1, 1, 0], [2, 4, ...

Let's switch the first two rows to get a 1 as the (1,1) entry (we could also multiply row 1 by -1).

> B:=swaprow(A,1,2);

B := matrix([[1, 1, 1, 0], [-1, 1, -1, -8], [2, 4, ...

Now add suitable multiples of the first row to each of the second and third rows. Note that a colon instead of a semicolon suppresses printing the result of a command, which allows for multiple commands on one input line. Using the colon in the command with(linalg) would suppress the list of commands in the linalg package.

> B:=addrow(B,1,2,1): B:=addrow(B,1,3,-2);

B := matrix([[1, 1, 1, 0], [0, 2, 0, -8], [0, 2, 6,...

Multiply row 2 by 1/2 to get a leading 1 in row 2 (note Maple does rational arithmetic exactly).

> B:=mulrow(B,2,1/2);

B := matrix([[1, 1, 1, 0], [0, 1, 0, -4], [0, 2, 6,...

Add a suitable multiple of row 2 to row 3 to clear out the (3,2) entry.

> B:=addrow(B,2,3,-2);

B := matrix([[1, 1, 1, 0], [0, 1, 0, -4], [0, 0, 6,...

> B:=mulrow(B,3,1/6);

B := matrix([[1, 1, 1, 0], [0, 1, 0, -4], [0, 0, 1,...

Now solve the system using backsubstitution.

Maple will automate the process of row reducing even further:

> gausselim(A);

matrix([[-1, 1, -1, -8], [0, 2, 0, -8], [0, 0, 6, 6...

Note that gausselim does not produce leading 1's

> gaussjord(A);

matrix([[1, 0, 0, 3], [0, 1, 0, -4], [0, 0, 1, 1]])...

The same result is given by rref (= reduced row echelon form)

> rref(A);

matrix([[1, 0, 0, 3], [0, 1, 0, -4], [0, 0, 1, 1]])...

>

>