Finding D matrix in LDU in matlab

6.1k Views Asked by At

I have been searching the web for nearly 3 hours about a MatLab function that can take matrix A and give me back L, D, and U. Does such function exist in MatLab?

Please feel free to change the title of the question if you think it's not expressive enough.

2

There are 2 best solutions below

0
On BEST ANSWER

This can be performed in Matlab as follows:

Given matrix A.

[L,U,P] = lu(A); % calculate partial-pivoted LU decomposition of A

D = diag(diag(U)); % get diagonal matrix

U = D\U; % the 'U' that is needed is really inv(D)*U

This allows you to write $LDU = PA$, where $P$ is a permutation matrix.

2
On

Matlab's lu function will find a LU decomposition of $A=LU$, then you can always write $U$ as $U=D\cdot \tilde U$ so $\tilde U$ has ones on the diagonal and $D$ is diagonal.