# lu

LU matrix factorization.

## Syntax

* \[L, U] = lu(A)
* \[L, U, P] = lu(A)

## Input argument

* A - a matrix: square, finite single or double.

## Output argument

* L - Lower triangular factor: matrix (same type A)
* U - Upper triangular factor: matrix (same type A).
* P - Row permutation: matrix (same type A).

## Description

\[L, U] = lu(A) function decomposes a full matrix A into two matrices: an upper triangular matrix U and a permuted lower triangular matrix L.

This factorization satisfies the equation A = L \* U.

\[L, U, P] = lu(A) function, when used with three output arguments, provides a permutation matrix P in addition to the unit lower triangular matrix L and the upper triangular matrix U.

This factorization is expressed as A = P'LU, where L is unit lower triangular, and U is upper triangular.

Used function(s)

LAPACKE\_dgetrf, LAPACKE\_sgetrf, LAPACKE\_zgetrf, LAPACKE\_cgetrf

## Examples

```matlab
A = magic(5)
[L, U] = lu(A)
L * U
```

```matlab
A = magic(5)
[L, U, P] = lu(A);
subplot(1, 2, 1)
spy(L)
title(_('L factor'))
subplot(1, 2, 2)
spy(U)
title(_('U factor'))
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-ddbf7b7a737a2dbb1544c09473444112b85afe3c%2Flu_6FD47B49.svg?alt=media)

## See also

[cond](cond).

## History

| Version | Description     |
| ------- | --------------- |
| 1.1.0   | initial version |

## Author

Allan CORNET
