code: public Matrix power(int n) {
          if (n < 0) {
              fail("The exponent should be positive: " + n + ".");
          }
  
          Matrix result = blankOfShape(rows, rows);
          Matrix that = this;
  
          for (int i = 0; i < rows; i++) {
              result.set(i, i, 1.0);
          }
  
          while (n > 0) {
              if (n % 2 == 1) {
                  result = result.multiply(that);
              }
  
              n /= 2;
              that = that.multiply(that);
          }
  
          return result;
      }
docs: Powers this matrix of given exponent {code n}.
  
  @param n the exponent
  
  @return the powered matrix