summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-01 06:21:24 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-01 06:21:24 +0000
commit59a3d59496607ebeb618fd781d3af9a6bc8c647e (patch)
treef62bad8a888a48f5062304c84b34eff8ee32db31 /lib
parent004c34f9de58067e627eb714083ca99b17e3fcfd (diff)
* lib/matrix.rb: Allow non integer exponents for Matrix#**
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/matrix.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 8c6b3d6..5ce1302 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -956,8 +956,10 @@ class Matrix
private :inverse_from
#
- # Matrix exponentiation. Currently implemented for integer powers only.
+ # 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
@@ -977,8 +979,9 @@ class Matrix
return z if (other >>= 1).zero?
x *= x
end
- when Float, Rational
- Matrix.Raise ErrOperationNotImplemented, "**", self.class, other.class
+ when Numeric
+ v, d, v_inv = eigensystem
+ v * Matrix.diagonal(*d.each(:diagonal).map{|e| e ** other}) * v_inv
else
Matrix.Raise ErrOperationNotDefined, "**", self.class, other.class
end