Reduced row echelon form: Difference between revisions

Reduced row echelon form in BASIC256
m (→‎Row operations, procedural code: house-keeping phase 2: tidy section #2)
(Reduced row echelon form in BASIC256)
Line 759:
[-0,1,0,1]
[-0,-0,1,-2]</pre>
 
=={{header|BASIC256}}==
<lang BASIC256>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</lang>
 
 
=={{header|BBC BASIC}}==
2,169

edits