ph-math/src/main/java/com/helger/numbercruncher/matrix/LinearSystem.java
private void _forwardElimination (final float scales[]) throws MatrixException
  {
    // Loop once per pivot row 0..nRows-1.
    for (int rPivot = 0; rPivot < m_nRows - 1; ++rPivot)
    {
      float largestScaledElmt = 0;
      int rLargest = 0;

      // Starting from the pivot row rPivot, look down
      // column rPivot to find the largest scaled element.
      for (int r = rPivot; r < m_nRows; ++r)
      {

        // Use the permuted row index.
        final int pr = m_aPermutation[r];
        final float absElmt = Math.abs (m_aLU.at (pr, rPivot));
        final float scaledElmt = absElmt * scales[pr];

        if (largestScaledElmt < scaledElmt)
        {

          // The largest scaled element and
          // its row index.
          largestScaledElmt = scaledElmt;
          rLargest = r;
        }
      }

      // Is the matrix singular?
      if (largestScaledElmt == 0)
      {
        throw new MatrixException (MatrixException.SINGULAR);
      }

      // Exchange rows if necessary to choose the best
      // pivot element by making its row the pivot row.
      if (rLargest != rPivot)
      {
        final int temp = m_aPermutation[rPivot];
        m_aPermutation[rPivot] = m_aPermutation[rLargest];
        m_aPermutation[rLargest] = temp;

        ++m_nExchangeCount;
      }

      // Use the permuted pivot row index.
      final int prPivot = m_aPermutation[rPivot];
      final float pivotElmt = m_aLU.at (prPivot, rPivot);

      // Do the elimination below the pivot row.
      for (int r = rPivot + 1; r < m_nRows; ++r)
      {

        // Use the permuted row index.
        final int pr = m_aPermutation[r];
        final float multiple = m_aLU.at (pr, rPivot) / pivotElmt;

        // Set the multiple into matrix L.
        m_aLU.set (pr, rPivot, multiple);

        // Eliminate an unknown from matrix U.
        if (multiple != 0)
        {
          for (int c = rPivot + 1; c < m_nCols; ++c)
          {
            float elmt = m_aLU.at (pr, c);

            // Subtract the multiple of the pivot row.
            elmt -= multiple * m_aLU.at (prPivot, c);
            m_aLU.set (pr, c, elmt);
          }
        }
      }
    }
  }
private void _forwardElimination (final float scales[]) throws MatrixException
  {
    // Loop once per pivot row 0..nRows-1.
    for (int rPivot = 0; rPivot < m_nRows - 1; ++rPivot)
    {
      float largestScaledElmt = 0;
      int rLargest = 0;

      // Starting from the pivot row rPivot, look down
      // column rPivot to find the largest scaled element.
      for (int r = rPivot; r < m_nRows; ++r)
      {

        // Use the permuted row index.
        final int pr = m_aPermutation[r];
        final float absElmt = Math.abs (m_aLU.at (pr, rPivot));
        final float scaledElmt = absElmt * scales[pr];

        if (largestScaledElmt < scaledElmt)
        {

          // The largest scaled element and
          // its row index.
          largestScaledElmt = scaledElmt;
          rLargest = r;
        }
      }

      // Is the matrix singular?
      if (largestScaledElmt == 0)
      {
        throw new MatrixException (MatrixException.SINGULAR);
      }

      // Exchange rows if necessary to choose the best
      // pivot element by making its row the pivot row.
      if (rLargest != rPivot)
      {
        final int temp = m_aPermutation[rPivot];
        m_aPermutation[rPivot] = m_aPermutation[rLargest];
        m_aPermutation[rLargest] = temp;

        ++m_nExchangeCount;
      }

      // Use the permuted pivot row index.
      final int prPivot = m_aPermutation[rPivot];
      final float pivotElmt = m_aLU.at (prPivot, rPivot);

      // Do the elimination below the pivot row.
      for (int r = rPivot + 1; r < m_nRows; ++r)
      {

        // Use the permuted row index.
        final int pr = m_aPermutation[r];
        final float multiple = m_aLU.at (pr, rPivot) / pivotElmt;

        // Set the multiple into matrix L.
        m_aLU.set (pr, rPivot, multiple);

        // Eliminate an unknown from matrix U.
        if (multiple != 0)
        {
          for (int c = rPivot + 1; c < m_nCols; ++c)
          {
            float elmt = m_aLU.at (pr, c);

            // Subtract the multiple of the pivot row.
            elmt -= multiple * m_aLU.at (prPivot, c);
            m_aLU.set (pr, c, elmt);
          }
        }
      }
    }
  }
Do forward elimination with scaled partial row pivoting.

@parm scales the scaling vector
@throws MatrixException
for a singular matrix