Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Ok, I've been working on a matrix solver for a while (no, its not going well, thanks for asking), and just discovered something that worrys me alot;

The problem at hand is LU Decomposition of a square matrix, for example

$\begin{matrix} 1&2&3\\ 2&-1&1\\ 3&4&-1\\ \end{matrix}$

WolframAlpha's answer is completely different from the example source


$\begin{matrix} 1&2&3\\ 3&-2&-10\\ 2&2.5&20\\ \end{matrix}$


$\begin{matrix} 1&2&3\\ 2&-5&-5\\ 3&0.4&-8\\ \end{matrix}$

What's going on?

share|cite|improve this question
I think your example source has some problem. Compare equation (3) with equation (6). $A$ is supposed to equal $LU$... –  Willie Wong Apr 17 '11 at 22:43
The Wolfram one also ends up being trying to take the LU decomposition of a row permutation of $A$. (It is the one for with the bottom two rows switched.) –  Willie Wong Apr 17 '11 at 22:51
@Willie: The example source is correct. Equation (6) you're referring to is showing how to store the $LU$ decomposition efficiently in one matrix. –  t.b. Apr 17 '11 at 22:52
@Theo: ah, thanks, I didn't pay enough attention. –  Willie Wong Apr 17 '11 at 22:55
Also, I think the question statement has a typo. Entry $(2,2)$ of the Wolfram compact representation should be $-2$ instead of $-1$. –  cardinal Apr 17 '11 at 23:02

1 Answer 1

up vote 7 down vote accepted

It looks like Wolfram Alpha is doing an LU decomposition with partial pivoting. So, it's actually solving a system like $$\newcommand{\bm}[1]{\mathbf{#1}} \bm{P} \bm{A} = \bm{L} \bm{U} $$ where $\bm{P}$ is a permutation matrix.

Curiously, it appears that Alpha simply isn't listing the permutation used in solving the system. In this case it is $$ \bm{P} = \left( \begin{matrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0 \end{matrix} \right) . $$

This is a common technique to enhance numerical stability.

You can recover $\bm{A}$ via $$ \bm{A} = \bm{P}^{-1} \bm{L} \bm{U} = \bm{P L U} $$ since in this case $\bm{P} = \bm{P}^{-1}$.

share|cite|improve this answer
So both are correct but WA is swapping around A before decomposition? –  Andrew Bolster Apr 17 '11 at 23:07
I didn't check closely the other solution, but the Wolfram one is correct when the permutation is included. –  cardinal Apr 18 '11 at 0:00

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.