55 lines
1.2 KiB
Text
55 lines
1.2 KiB
Text
arraybase 1
|
|
global matrix
|
|
dim matrix = {{1, 2, -1, -4}, {2, 3, -1, -11}, { -2, 0, -3, 22}}
|
|
|
|
call RREF (matrix)
|
|
|
|
for row = 1 to 3
|
|
for col = 1 to 4
|
|
if matrix[row, col] = 0 then
|
|
print "0"; chr(9);
|
|
else
|
|
print matrix[row, col]; chr(9);
|
|
end if
|
|
next
|
|
print
|
|
next
|
|
end
|
|
|
|
subroutine RREF(m)
|
|
nrows = matrix[?,]
|
|
ncols = matrix[,?]
|
|
lead = 1
|
|
for r = 1 to nrows
|
|
if lead >= ncols then exit for
|
|
i = r
|
|
while matrix[i, lead] = 0
|
|
i += 1
|
|
if i = nrows then
|
|
i = r
|
|
lead += 1
|
|
if lead = ncols then exit for
|
|
end if
|
|
end while
|
|
for j = 1 to ncols
|
|
temp = matrix[i, j]
|
|
matrix[i, j] = matrix[r, j]
|
|
matrix[r, j] = temp
|
|
next
|
|
n = matrix[r, lead]
|
|
if n <> 1 then
|
|
for j = 0 to ncols
|
|
matrix[r, j] /= n
|
|
next
|
|
end if
|
|
for i = 1 to nrows
|
|
if i <> r then
|
|
n = matrix[i, lead]
|
|
for j = 1 to ncols
|
|
matrix[i, j] -= matrix[r, j] * n
|
|
next
|
|
end if
|
|
next
|
|
lead += 1
|
|
next
|
|
end subroutine
|