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

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