public static Matrix backSub(Matrix U,Matrix y){
  if (y.rows() != U.rows())   throw new ArithmeticException("Vector and matrix sizes do not agree");
  Matrix x=new DenseMatrix(U.cols(),y.cols());
  double[] x_col_k=new double[y.rows()];
  final int start=Math.min(U.rows(),U.cols()) - 1;
  for (int k=0; k < y.cols(); k++) {
    for (int i=start; i >= 0; i--) {
      x_col_k[i]=y.get(i,k);
      for (int j=i + 1; j <= start; j++)       x_col_k[i]-=U.get(i,j) * x_col_k[j];
      x_col_k[i]/=U.get(i,i);
    }
    for (int i=0; i < x_col_k.length; i++)     if (Double.isInfinite(x_col_k[i]))     x.set(i,k,0);
 else     x.set(i,k,x_col_k[i]);
  }
  return x;
}

public static Matrix backSub ( Matrix U , Matrix y ) { if ( y . rows ( ) != U . rows ( ) ) throw new ArithmeticException ( "Vector and matrix sizes do not agree" ) ; Matrix x = new DenseMatrix ( U . cols ( ) , y . cols ( ) ) ; double [ ] x_col_k = new double [ y . rows ( ) ] ; final int start = Math . min ( U . rows ( ) , U . cols ( ) ) - 1 ; for ( int k = 0 ; k < y . cols ( ) ; k ++ ) { for ( int i = start ; i >= 0 ; i -- ) { x_col_k [ i ] = y . get ( i , k ) ; for ( int j = i + 1 ; j <= start ; j ++ ) x_col_k [ i ] -= U . get ( i , j ) * x_col_k [ j ] ; x_col_k [ i ] /= U . get ( i , i ) ; } for ( int i = 0 ; i < x_col_k . length ; i ++ ) if ( Double . isInfinite ( x_col_k [ i ] ) ) x . set ( i , k , 0 ) ; else x . set ( i , k , x_col_k [ i ] ) ; } return x ; }
solves for the matrix x such that u x = y
