```いけがみです．

[ruby-math:00284] で，るびきちさんが見つけた matrix.rb の
バグの修正を改めて書きました．
# こんどは GNU diff -u で作りました．

#!/usr/bin/ruby
require 'matrix'
p Matrix[[1,2,3],[-4,-5,-6]].rank
---> 2

p Matrix[[1,2],[-3,-4],[5,6]].rank
---> 2

るびきちさんの mathx はとても興味があるのですが，
BLAS や LAPACK のインストールがまだ済んでいないので

# ようやく，GNU diff のインストールの仕方を教えてもらったばかりなのです．

--

Daisuke IKEGAMI <daisu-ik / is.aist-nara.ac.jp>

--- matrix.rb	Fri May 12 17:30:22 2000
+++ matrix.rb	Tue Aug 29 05:31:43 2000
@@ -614,8 +614,12 @@
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
@@ -624,7 +628,7 @@
i = k
exists = true
begin
-	  if (i += 1) > column_size - 1
+	  if (i += 1) > a_column_size - 1
exists = false
break
end
@@ -636,13 +640,13 @@
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
@@ -652,16 +656,16 @@
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

```