Ralph Schleicher
and 1 contributors


Math::MatrixDecomposition::LU - LU decomposition


Object-oriented interface.

    use Math::MatrixDecomposition::LU;

    $LU = Math::MatrixDecomposition::LU->new;
    $LU->decompose ($A = [...]);
    $LU->solve ($b = [...]);

    # Decomposition is the default action for 'new'.
    # This one-liner is equivalent to the command sequence above.
    Math::MatrixDecomposition::LU->new ($A = [...])->solve ($b = [...]);

The procedural form is even shorter.

    use Math::MatrixDecomposition qw(lu);

    lu ($A = [...])->solve ($b = [...]);


Object Instantiation

lu (...)

The lu function is the short form of Math::MatrixDecomposition::LU->new (which see). The lu function has to be used as a subroutine. It is not exported by default.

new (...)

Create a new object. Any arguments are forwarded to the decompose method (which see). The new constructor can be used as a class or instance method.

Instance Methods

decompose (a, m, n, ...)

Perform a LU decomposition with partial pivoting of a real matrix.

  • First argument a is an array reference to the matrix elements. Matrix elements are interpreted in row-major layout.

  • Optional second argument m is the number of matrix rows. If omitted, it is assumed that the matrix is square.

  • Optional third argument n is the number of matrix columns. If omitted, the number of matrix columns is calculated automatically.

  • Remaining arguments are property/value pairs with the following meaning.

    capture flag

    Whether or not to decompose the matrix a in-place. Default is false.

Return value is the LU object.

solve (b, x)

Solve a system of linear equations 'A X = B'.

The LU object represents the coefficients of the left-hand side of the system, that is the matrix 'A'.

  • First argument b is an array reference. Array elements are the right-hand side of the system. Argument b may have more than one column (matrix elements of b are interpreted in row-major layout).

  • Optional second argument x is an array reference. The solution of the system is saved in x. Default is to save the solution in place of b.

Return value is the solution x.


Return the value of the determinant.




Ralph Schleicher <ralph@cpan.org>