**(other)
public
Matrix exponentiation. Equivalent to multiplying
the matrix by itself N times. Non integer exponents will be handled by
diagonalizing the matrix.
Matrix[[7,6], [3,9]] ** 2
=> 67 96
48 99
Show source
def **(other)
case other
when Integer
x = self
if other <= 0
x = self.inverse
return self.class.identity(self.column_count) if other == 0
other = -other
end
z = nil
loop do
z = z ? z * x : x if other[0] == 1
return z if (other >>= 1).zero?
x *= x
end
when Numeric
v, d, v_inv = eigensystem
v * self.class.diagonal(*d.each(:diagonal).map{|e| e ** other}) * v_inv
else
Matrix.Raise ErrOperationNotDefined, "**", self.class, other.class
end
end