0
$\begingroup$

I created an upper triangular matrix in U and a lower triangular matrix L from A matrix but when I go to make the inverse procedure in order to take my original matrix the matlab returns the right elements in right row and column but the rows are in wrong place. What I do wrong?

A=[1 -2 3;9 2 1;4 -3 2]
[L,U,P]=lu(A)
B=P*A
C=L*U

A =

 1    -2     3
 9     2     1
 4    -3     2

L =

1.0000         0         0
0.4444    1.0000         0
0.1111    0.5714    1.0000

U =

9.0000    2.0000    1.0000
     0   -3.8889    1.5556
     0         0    2.0000

P =

 0     1     0
 0     0     1
 1     0     0

B =

 9     2     1
 4    -3     2
 1    -2     3

C =

 9     2     1
 4    -3     2
 1    -2     3
$\endgroup$
2
  • $\begingroup$ Isn't it C=PLU? $\endgroup$
    – 7raiden7
    Mar 26, 2014 at 12:18
  • $\begingroup$ with this C=PLU it returns: C = |4 -3 2| 1 -2 3| 9 2 1| $\endgroup$
    – 2 X
    Mar 26, 2014 at 13:33

2 Answers 2

1
$\begingroup$

MatLab does a strange trick, namely: $$ A=P^{-1}LU, $$ so just pose: $$ B=P^{-1}LU, $$ and verify that $A=B$.

$\endgroup$
0
$\begingroup$

From MATLAB's documentation

[L,U,P] = lu(A) returns an upper triangular matrix in U, a lower triangular matrix L with a unit diagonal, and a permutation matrix P, such that L*U = P*A. The statement lu(A,'matrix') returns identical output values.

MATLAB gives you, in essence, the $L$ and $U$ that return you a permutation of $A$. But since this permutation is easily invertible, you can either consider

$$PA = LU$$ or $$A = P^{-1}LU.$$

However, $P$ is orthogonal, so $P^{-1} = P^T$, so you can confirm the following result in MATLAB code:

A=[1 -2 3;9 2 1;4 -3 2];
[L,U,P]=lu(A);
A-P'*L*U % This should have entries very very small.
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .