Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the algorithm for LU factorization in MATLAB, i.e. [L,U] = lu(a)?

After searching for many examples and trying to compare the result with MATLAB, they are all different.

However, I would like to do the result as it is in MATLAB. Which books contain the algorithm; or, what is exact algorithm used?

a = [1,2,3;4,5,6;7,8,9]
[L,U] = lu(a)

I Googled this, and it is different from MATLAB:

share|cite|improve this question
MATLAB does $PA = LU$ where $P$ is the permutation matrix to do row pivoting and returns $PL$ and $U$. – user17762 May 6 '12 at 1:34
"After googled many examples and try to compare the result with Matlab, they are all different." - can you give an example of what you get from MATLAB and what you see in your Google searches? We might be able to be more helpful if you provide more detail than you now have. – J. M. May 6 '12 at 1:51
added in question – Agul May 6 '12 at 3:41
Well, one problem with your example is that it's singular; a floating-point implementation of LU might yield diagonal elements that are tiny, but not zero, due to floating-point error... – J. M. May 6 '12 at 4:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.