OnLine3-5-LU.mws

Linear Algebra Powertool

The LU Decomposition

OnLine 3.5

Worksheet 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 investigates the LU decomposition of a matrix.

The basic objectives are:

Finding an LU decomposition

First define a random 3 x 4 matrix.

> A := randmatrix(3,4,entries=rand(-5..5));

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

Let's keep track of the elementary matrices corresponding to the row operations used, as well as the cumulative product of the elementary matrices, which we can do by starting with the matrix A augmented by the appropriate identity matrix:

> Iden:=evalm(array(identity, 1..3,1..3));
AAug := augment(A,Iden);

Iden := matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

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

Now we apply elementary row operations to the augmented matrix. We hope to add multiples of rows to lower rows to get a row echelon form. We exhibit the elementary matrices at each step.

(Note that the matrix A is not truly "random" - every time the worksheet is started, it produces the same matrix A. Thus we know in advance which row operations are required in this worksheet. This is handy for teaching purposes. If you want a truly "random" matrix, you need to precede the randmatrix command with a "randomize()", which generates a seed for the random functions in Maple, based on the computer clock.)

> AAugR := addrow(AAug,1,2,1/4);
E := addrow(Iden,1,2,1/4);

AAugR := matrix([[4, -1, -4, -1, 1, 0, 0], [0, -17/...

E := matrix([[1, 0, 0], [1/4, 1, 0], [0, 0, 1]])

> AAugR := addrow(AAugR,1,3,-1);
E := addrow(Iden,1,3,-1);

AAugR := matrix([[4, -1, -4, -1, 1, 0, 0], [0, -17/...

E := matrix([[1, 0, 0], [0, 1, 0], [-1, 0, 1]])

> AAugR := addrow(AAugR,2,3,5*4/17);
E := addrow(Iden,2,3,5*4/17);

AAugR := matrix([[4, -1, -4, -1, 1, 0, 0], [0, -17/...

E := matrix([[1, 0, 0], [0, 1, 0], [0, 20/17, 1]])

AAugR is in row echelon form. Note we don't bother to force leading ones. The matrix U can now be extracted:

> U := delcols(AAugR,5..7);

U := matrix([[4, -1, -4, -1], [0, -17/4, -3, 11/4],...

The matrix B referred to in class can also be extracted:

> B := delcols(AAugR,1..4);

B := matrix([[1, 0, 0], [1/4, 1, 0], [-12/17, 20/17...

The matrix L we seek is just the inverse of this B:

> L := inverse(B);

L := matrix([[1, 0, 0], [-1/4, 1, 0], [1, -20/17, 1...

Now note the remarkable relationship between the entries of L, the elementary matrices, and the multipliers used in the row reductions! The matrix L can in fact be written down without actually computing the inverse of B.

Check that A = LU

> evalm(L &* U); evalm(A);

matrix([[4, -1, -4, -1], [-1, -4, -2, 3], [4, 4, -3...

matrix([[4, -1, -4, -1], [-1, -4, -2, 3], [4, 4, -3...

Exercise:

1) Repeat the above for a random 4 x 4 matrix AA (be careful not to reuse any of the variable names used previously, since some get reused below!)

Now let's see how to use the LU decomposition to solve a system AX = Y

Let's generate a RHS vector Y

> Y := randmatrix(3,1,entries=rand(-5..5));

Y := matrix([[4], [-1], [0]])

Solve LZ = Y for Z; note this amounts to a simple forward-substitution (no further row reductions). We show the augmented matrix and have Maple compute.

> augment(L,Y);
Z:=linsolve(L,Y);

matrix([[1, 0, 0, 4], [-1/4, 1, 0, -1], [1, -20/17,...

Z := matrix([[4], [0], [-4]])

Then solve UX = Z for X; note this amounts to a simple back-substitution (no further row reductions). We show the augmented matrix and again have Maple compute the solution for us.

> augment(U,Z);
X := linsolve(U,Z);

matrix([[4, -1, -4, -1, 4], [0, -17/4, -3, 11/4, 0]...

X := matrix([[69/13+35/13*_t[1][1]], [_t[1][1]], [4...

(Unfortunately Maple does not always select the parameter the way we do.)

Exercise:

2) Generate a random 4 x 1 vector YY, and then repeat the steps above to solve (AA)(X) = YY.

>

3) What advantage would the LU decomposition have for computer computation of solutions to linear systems?

4) Use Maple's help command to find out about the LUdecomp command in the linalg package, Use the command to check your LU decomposition of AA in exercise 1.

>

>

>

>