Class LUDecomposition

  • All Implemented Interfaces:
    java.io.Serializable

    public class LUDecomposition
    extends java.lang.Object
    implements java.io.Serializable
    LU Decomposition.

    For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a permutation vector piv of length m so that A(piv,:) = L*U. If m < n, then L is m-by-m and U is m-by-n.

    The LU decompostion with pivoting always exists, even if the matrix is singular, so the constructor will never fail. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations. This will fail if isNonsingular() returns false.

    Since:
    0.1
    Author:
    Arthur Zimek
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double[][] LU
      Array for internal storage of decomposition.
      private int m
      Row and column dimensions, and pivot sign.
      private int n
      Row and column dimensions, and pivot sign.
      private int[] piv
      Internal storage of pivot vector.
      private int pivsign
      Row and column dimensions, and pivot sign.
      private static long serialVersionUID
      Serial version
    • Constructor Summary

      Constructors 
      Constructor Description
      LUDecomposition​(double[][] LU)
      LU Decomposition
      LUDecomposition​(double[][] LU, int m, int n)
      LU Decomposition
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double det()
      Determinant
      double[][] getL()
      Return lower triangular factor
      int[] getPivot()
      Return pivot permutation vector
      double[][] getU()
      Return upper triangular factor
      double[][] inverse()
      Find the inverse matrix.
      boolean isNonsingular()
      Is the matrix nonsingular?
      double[] solve​(double[] b)
      Solve A*X = b
      double[][] solve​(double[][] B)
      Solve A*X = B
      double[] solveInplace​(double[] b)
      Solve A*X = b
      private double[][] solveInplace​(double[][] B)
      Solve A*X = B
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Serial version
        See Also:
        Constant Field Values
      • LU

        private double[][] LU
        Array for internal storage of decomposition.
      • m

        private int m
        Row and column dimensions, and pivot sign.
      • n

        private int n
        Row and column dimensions, and pivot sign.
      • pivsign

        private int pivsign
        Row and column dimensions, and pivot sign.
      • piv

        private int[] piv
        Internal storage of pivot vector.
    • Constructor Detail

      • LUDecomposition

        public LUDecomposition​(double[][] LU)
        LU Decomposition
        Parameters:
        LU - Rectangular matrix
      • LUDecomposition

        public LUDecomposition​(double[][] LU,
                               int m,
                               int n)
        LU Decomposition
        Parameters:
        LU - Rectangular matrix
        m - row dimensionality
        n - column dimensionality
    • Method Detail

      • isNonsingular

        public boolean isNonsingular()
        Is the matrix nonsingular?
        Returns:
        true if U, and hence A, is nonsingular.
      • getL

        public double[][] getL()
        Return lower triangular factor
        Returns:
        L
      • getU

        public double[][] getU()
        Return upper triangular factor
        Returns:
        U
      • getPivot

        public int[] getPivot()
        Return pivot permutation vector
        Returns:
        piv
      • det

        public double det()
        Determinant
        Returns:
        det(A)
        Throws:
        java.lang.IllegalArgumentException - Matrix must be square
      • solve

        public double[][] solve​(double[][] B)
        Solve A*X = B
        Parameters:
        B - A Matrix with as many rows as A and any number of columns.
        Returns:
        X so that L*U*X = B(piv,:)
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is singular.
      • solveInplace

        private double[][] solveInplace​(double[][] B)
        Solve A*X = B
        Parameters:
        B - A Matrix with as many rows as A and any number of columns.
        Returns:
        B
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is singular.
      • solve

        public double[] solve​(double[] b)
        Solve A*X = b
        Parameters:
        b - A column vector with as many rows as A
        Returns:
        X so that L*U*X = b(piv)
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is singular.
      • solveInplace

        public double[] solveInplace​(double[] b)
        Solve A*X = b
        Parameters:
        b - A vector
        Returns:
        b
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is singular.
      • inverse

        public double[][] inverse()
        Find the inverse matrix.
        Returns:
        Inverse matrix
        Throws:
        java.lang.ArithmeticException - Matrix is rank deficient.