diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-09-01 03:31:05 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-09-01 03:31:05 +0000 |
commit | 80bec905cbb7719a4f241ae859fa705a8d265894 (patch) | |
tree | 4bc848c3b8cdde1032611e27217cec98134055e2 /lib | |
parent | be37634ffbc46ce3d839b94989be644720fed517 (diff) | |
download | ruby-80bec905cbb7719a4f241ae859fa705a8d265894.tar.gz ruby-80bec905cbb7719a4f241ae859fa705a8d265894.tar.xz ruby-80bec905cbb7719a4f241ae859fa705a8d265894.zip |
matz
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/matrix.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb index 223bf7086..4821babab 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -612,8 +612,12 @@ class Matrix def rank if column_size > row_size a = transpose.to_a + a_column_size = row_size + a_row_size = column_size else a = to_a + a_column_size = column_size + a_row_size = row_size end rank = 0 k = 0 @@ -622,7 +626,7 @@ class Matrix i = k exists = true begin - if (i += 1) > column_size - 1 + if (i += 1) > a_column_size - 1 exists = false break end @@ -634,13 +638,13 @@ class Matrix i = k exists = true begin - if (i += 1) > row_size - 1 + if (i += 1) > a_row_size - 1 exists = false break end end while a[k][i] == 0 if exists - k.upto(column_size - 1) do + k.upto(a_column_size - 1) do |j| a[j][k], a[j][i] = a[j][i], a[j][k] end @@ -650,16 +654,16 @@ class Matrix end end end - (k + 1).upto(row_size - 1) do + (k + 1).upto(a_row_size - 1) do |i| q = a[i][k] / akk - (k + 1).upto(column_size - 1) do + (k + 1).upto(a_column_size - 1) do |j| a[i][j] -= a[k][j] * q end end rank += 1 - end while (k += 1) <= column_size - 1 + end while (k += 1) <= a_column_size - 1 return rank end |