LDU Factorization in MatLab

2.6k Views Asked by At

I am working on a project in linear systems which requires me to do LDU Decomposition on a given 6x6 matrix. For the first part of the project he wants wants this computed fully by hand. What I am having trouble with is the second part where we are meant to be doing it using for-loops in matlab. We are given random 6x6 and 15x15 matrices and asked to find L D U and their inverses in addition to he inverse of our original matrix. "The MATLAB script must find these via row operations computed inside for-loops, you absolutely ma not use inv(), rref(), or other such commands." Can someone give me some basics tips as to where I should begin?

2

There are 2 best solutions below

5
On

Here

A = rand(6,6); % random 6x6 matrix

[L,U,~] = lu(A); % do an LU decomposition, using MATLAB's lu method.
D = diag(diag(U)); % take the diagonal components of matrix U and store them in the diagonal matrix D 
U = inv(D)*U; % clean the U matrix as follows
0
On

Here are some hints:

Create a matrix:

M = rand(6,6);

Extract the i-th column from this matrix:

c = M(:,i) 

Extract the j-th line from this matrix:

v = M(j,:)

Matrix multiply them (kinda like a dot product)

prod = v*c

Get elements from 2 to 6 (end) in the j-th line:

v2 = M(j,2:end)

Hope this helps.