Contents

LU factorization

finds the LU factorization of a given matrix A using only pivots on the diagonal (ie: LU factorization like we did in class)

function [L,U]=LUfactorization(A)

Setting up the matrix

in order to use the lu() matlab function, A must be a sparse matrix

A=sparse(A);
Input argument "A" is undefined.

Error in ==> LUfactorization at 8
A=sparse(A);

Getting the LU factorization

now we use the built in matlab function the flag 0 on the end forces the pivots to be on the diagonal the default for this function is 1, which uses a modified version of the lu function, which we haven't learned L is the unit lower triangular matrix U is the upper triangular matrix P is called the permutation matrix, if we can find our LU factorization then P will be the identity matrix

[L,U,P]=lu(A,0);

Putting matrices into full form

L=full(L);
U=full(U);