public static double[] solveTriangle(Matrix t,double[] b,boolean isLower,boolean[] isZero){
  int n=b.length;
  double[] result=new double[n];
  if (isZero == null) {
    isZero=new boolean[n];
  }
  if (isLower) {
    int j=0;
    while ((j < n) && isZero[j]) {
      result[j]=0.0;
      j++;
    }
    if (j < n) {
      result[j]=b[j] / t.get(j,j);
      for (; j < n; j++) {
        if (!isZero[j]) {
          double numerator=b[j];
          for (int k=0; k < j; k++) {
            numerator-=t.get(j,k) * result[k];
          }
          result[j]=numerator / t.get(j,j);
        }
 else {
          result[j]=0.0;
        }
      }
    }
  }
 else {
    int j=n - 1;
    while ((j >= 0) && isZero[j]) {
      result[j]=0.0;
      j--;
    }
    if (j >= 0) {
      result[j]=b[j] / t.get(j,j);
      for (; j >= 0; j--) {
        if (!isZero[j]) {
          double numerator=b[j];
          for (int k=j + 1; k < n; k++) {
            numerator-=t.get(k,j) * result[k];
          }
          result[j]=numerator / t.get(j,j);
        }
 else {
          result[j]=0.0;
        }
      }
    }
  }
  return result;
}

public static double [ ] solveTriangle ( Matrix t , double [ ] b , boolean isLower , boolean [ ] isZero ) { int n = b . length ; double [ ] result = new double [ n ] ; if ( isZero == null ) { isZero = new boolean [ n ] ; } if ( isLower ) { int j = 0 ; while ( ( j < n ) && isZero [ j ] ) { result [ j ] = 0.0 ; j ++ ; } if ( j < n ) { result [ j ] = b [ j ] / t . get ( j , j ) ; for ( ; j < n ; j ++ ) { if ( ! isZero [ j ] ) { double numerator = b [ j ] ; for ( int k = 0 ; k < j ; k ++ ) { numerator -= t . get ( j , k ) * result [ k ] ; } result [ j ] = numerator / t . get ( j , j ) ; } else { result [ j ] = 0.0 ; } } } } else { int j = n - 1 ; while ( ( j >= 0 ) && isZero [ j ] ) { result [ j ] = 0.0 ; j -- ; } if ( j >= 0 ) { result [ j ] = b [ j ] / t . get ( j , j ) ; for ( ; j >= 0 ; j -- ) { if ( ! isZero [ j ] ) { double numerator = b [ j ] ; for ( int k = j + 1 ; k < n ; k ++ ) { numerator -= t . get ( k , j ) * result [ k ] ; } result [ j ] = numerator / t . get ( j , j ) ; } else { result [ j ] = 0.0 ; } } } } return result ; }
solve the linear equation of tx = b where t is a triangle matrix it can be solved using back / forward substitution , with o ( n ^ 2 ) complexity
