aboutsummaryrefslogtreecommitdiffstats
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-29 01:13:22 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-29 01:13:22 +0000
commit54bbc098fa1e05570e960750bf2c86d45017e575 (patch)
tree2c10d54b1e3b477341ee99bbf57b5669c3714fac /lib/matrix.rb
parentde97e946f04dd0374d6f2580c97591bc1fdc1f3f (diff)
downloadruby-54bbc098fa1e05570e960750bf2c86d45017e575.tar.gz
* lib/matrix.rb: Matrix.zero can build rectangular matrices.
Vector#r should be called #magnitude git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 02c157801d..3242cde9b2 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -229,13 +229,14 @@ class Matrix
end
#
- # Creates an +n+ by +n+ zero matrix.
+ # Creates a zero matrix.
# Matrix.zero(2)
# => 0 0
# 0 0
#
- def Matrix.zero(n)
- Matrix.scalar(n, 0)
+ def Matrix.zero(row_size, column_size = row_size)
+ rows = Array.new(row_size){Array.new(column_size, 0)}
+ new rows, column_size
end
#
@@ -1723,9 +1724,10 @@ class Vector
# Returns the modulus (Pythagorean distance) of the vector.
# Vector[5,8,2].r => 9.643650761
#
- def r
+ def magnitude
Math.sqrt(@elements.inject(0) {|v, e| v + e*e})
end
+ alias r magnitude
#--
# CONVERTING