ph-math/src/main/java/com/helger/numbercruncher/matrix/LinearSystem.java
protected void decompose () throws MatrixException
  {
    // Return if the decomposition is valid.
    if (m_aLU != null)
      return;

    // Create a new LU matrix and permutation vector.
    // LU is initially just a copy of the values of this system.
    m_aLU = new SquareMatrix (this.copyValues2D ());
    m_aPermutation = new int [m_nRows];

    final float scales[] = new float [m_nRows];

    // Loop to initialize the permutation vector and scales.
    for (int r = 0; r < m_nRows; ++r)
    {
      m_aPermutation[r] = r; // initially no row exchanges

      // Find the largest row element.
      float largestRowElmt = 0;
      for (int c = 0; c < m_nRows; ++c)
      {
        final float elmt = Math.abs (m_aLU.at (r, c));
        if (largestRowElmt < elmt)
          largestRowElmt = elmt;
      }

      // Set the scaling factor for row equilibration.
      if (largestRowElmt != 0)
      {
        scales[r] = 1 / largestRowElmt;
      }
      else
      {
        throw new MatrixException (MatrixException.ZERO_ROW);
      }
    }

    // Do forward elimination with scaled partial row pivoting.
    _forwardElimination (scales);

    // Check bottom right element of the permuted matrix.
    if (m_aLU.at (m_aPermutation[m_nRows - 1], m_nRows - 1) == 0)
    {
      throw new MatrixException (MatrixException.SINGULAR);
    }
  }
protected void decompose () throws MatrixException
  {
    // Return if the decomposition is valid.
    if (m_aLU != null)
      return;

    // Create a new LU matrix and permutation vector.
    // LU is initially just a copy of the values of this system.
    m_aLU = new SquareMatrix (this.copyValues2D ());
    m_aPermutation = new int [m_nRows];

    final float scales[] = new float [m_nRows];

    // Loop to initialize the permutation vector and scales.
    for (int r = 0; r < m_nRows; ++r)
    {
      m_aPermutation[r] = r; // initially no row exchanges

      // Find the largest row element.
      float largestRowElmt = 0;
      for (int c = 0; c < m_nRows; ++c)
      {
        final float elmt = Math.abs (m_aLU.at (r, c));
        if (largestRowElmt < elmt)
          largestRowElmt = elmt;
      }

      // Set the scaling factor for row equilibration.
      if (largestRowElmt != 0)
      {
        scales[r] = 1 / largestRowElmt;
      }
      else
      {
        throw new MatrixException (MatrixException.ZERO_ROW);
      }
    }

    // Do forward elimination with scaled partial row pivoting.
    _forwardElimination (scales);

    // Check bottom right element of the permuted matrix.
    if (m_aLU.at (m_aPermutation[m_nRows - 1], m_nRows - 1) == 0)
    {
      throw new MatrixException (MatrixException.SINGULAR);
    }
  }
Compute the upper triangular matrix U and lower triangular matrix L such
that A = L*U. Store L and U together in matrix LU. Compute the permutation
vector permutation of the row indices.

@throws MatrixException
for a zero row or a singular matrix