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 | 2252d4ce028b38bb46310b215b2c98afbf224d55 (patch) | |
tree | 4bc848c3b8cdde1032611e27217cec98134055e2 /lib/matrix.rb | |
parent | 6001314def338002ae1dc50bcf120805bee78a44 (diff) |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-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 223bf70869..4821bababf 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 |