code: function triaUpSolve(A, b) {
      var size = A[0].length;
      var x = jStat.zeros(1, size)[0];
      var parts;
      var matrix_mode = false;
  
      if (b[0].length != undefined) {
        b = b.map(function(i){ return i[0] });
        matrix_mode = true;
      }
  
      jStat.arange(size - 1, -1, -1).forEach(function(i) {
        parts = jStat.arange(i + 1, size).map(function(j) {
          return x[j] * A[i][j];
        });
        x[i] = (b[i] - jStat.sum(parts)) / A[i][i];
      });
  
      if (matrix_mode)
        return x.map(function(i){ return [i] });
      return x;
    }
docs: solve equation Ax=b A is upper triangular matrix A=[[1,2,3],[0,4,5],[0,6,7]] b=[1,2,3] triaUpSolve(A,b) // -> [2.666,0.1666,1.666] if you use matrix style A=[[1,2,3],[0,4,5],[0,6,7]] b=[[1],[2],[3]] will return [[2.666],[0.1666],[1.666]]