## `linalg::inverseLU` -- computing the inverse of a matrix using LU-decomposition

#### Introduction

`linalg::inverseLU``(A)` computes the inverse A^(-1) of the square matrix A using LU-decomposition.

`linalg::inverseLU``(L, U, pivindex)` computes the inverse of the matrix A = P^(-1)*L*U where `L`, `U` and `pivindex` are the result of an LU-deomposition of the (nonsingular) Matrix A, as computed by `linalg::factorLU`.

#### Call(s)

`linalg::inverseLU(A)`
`linalg::inverseLU(L, U, pivindex)`

#### Parameters

`A, L, U` | - | a square matrix of a domain of category `Cat::Matrix`
`pivindex` | - | a list of positive integers

#### Returns

a matrix of the same domain type as `A` or `L`, respectively.

#### Related Functions

`_invert`, `linalg::factorLU`, `linalg::matlinsolveLU`

#### Details

- The matrix `A` must be nonsingular.
- `pivindex` is a list `[r[1], r[2], ...]` representing a permutation matrix P such that B = PA = LU, where B[i,j] = A[r[i],j].

  It is not checked whether `pivindex` has such a form.

- The component ring of the input matrices must be a field, i.e., a domain of category `Cat::Field`.

#### Example 1

We compute the inverse of the matrix:

    >> A := Dom::Matrix(Dom::Real)(
         [[2, -3, -1], [1, 1, -1], [0, 1, -1]]
       )

                                  +-           -+
                                  |  2, -3, -1  |
                                  |             |
                                  |  1,  1, -1  |
                                  |             |
                                  |  0,  1, -1  |
                                  +-           -+

using LU-decomposition:

    >> Ai := linalg::inverseLU(A)

                               +-                 -+
                               |    0,   1,   -1   |
                               |                   |
                               |  -1/4, 1/2, -1/4  |
                               |                   |
                               |  -1/4, 1/2, -5/4  |
                               +-                 -+

We check the result:

    >> A * Ai, Ai * A

                           +-         -+  +-         -+
                           |  1, 0, 0  |  |  1, 0, 0  |
                           |           |  |           |
                           |  0, 1, 0  |, |  0, 1, 0  |
                           |           |  |           |
                           |  0, 0, 1  |  |  0, 0, 1  |
                           +-         -+  +-         -+

We can also compute the inverse of A in the usual way:

    >> 1/A

                               +-                 -+
                               |    0,   1,   -1   |
                               |                   |
                               |  -1/4, 1/2, -1/4  |
                               |                   |
                               |  -1/4, 1/2, -5/4  |
                               +-                 -+

`linalg::inverseLU` should be used for efficiency reasons in the case where an LU decomposition of a matrix already is computed, as the next example illustrates.

#### Example 2

If we already have an LU decomposition of a (nonsingular) matrix, we can compute the inverse of the matrix A = P^(-1)*L*U as follows:

    >> LU := linalg::factorLU(linalg::hilbert(3))

              -- +-           -+  +-                -+            --
              |  |   1,  0, 0  |  |  1,  1/2,  1/3   |             |
              |  |             |  |                  |             |
              |  |  1/2, 1, 0  |, |  0, 1/12,  1/12  |, [1, 2, 3]  |
              |  |             |  |                  |             |
              |  |  1/3, 1, 1  |  |  0,   0,  1/180  |             |
              -- +-           -+  +-                -+            --

    >> linalg::inverseLU(op(LU))

                               +-                 -+
                               |   9,   -36,  30   |
                               |                   |
                               |  -36,  192, -180  |
                               |                   |
                               |   30, -180,  180  |
                               +-                 -+

`linalg::inverseLU` then only needs to perform forward and backward substitution to compute the inverse matrix (see also `linalg::matlinsolveLU`).

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000