**(other)
public
Matrix exponentiation. Currently implemented
for integer powers only. Equivalent to multiplying the matrix by itself N
times.
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 Matrix.identity(self.column_size) 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 Float, Rational
Matrix.Raise ErrOperationNotImplemented, "**", self.class, other.class
else
Matrix.Raise ErrOperationNotDefined, "**", self.class, other.class
end
end