summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--NEWS1
-rw-r--r--lib/matrix.rb9
3 files changed, 11 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d0d5808..a5c3ba9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Jul 1 15:21:14 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * lib/matrix.rb: Allow non integer exponents for Matrix#**
+
Fri Jul 1 15:13:25 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* lib/matrix: Add Eigenvalue Decomposition
diff --git a/NEWS b/NEWS
index dd6ab19..cee2bc0 100644
--- a/NEWS
+++ b/NEWS
@@ -178,6 +178,7 @@ with all sufficient information, see the ChangeLog file.
* Matrix#each and #each_with_index can iterate on a subset of the elements
* Matrix#find_index returns [row, column] and can iterate on a subset
of the elements
+ * Matrix#** implements Numeric exponents (using the eigensystem)
* Matrix.zero can build rectangular matrices
* net/http
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