Reduced row echelon form: Difference between revisions
Content added Content deleted
(Reduced row echelon form in BASIC256) |
(Reduced row echelon form in Yabasic) |
||
Line 4,523: | Line 4,523: | ||
| 0 0 1 -2| |
| 0 0 1 -2| |
||
</pre> |
</pre> |
||
=={{header|Yabasic}}== |
|||
<lang yabasic>// Rosetta Code problem: https://rosettacode.org/wiki/Reduced_row_echelon_form |
|||
// by Jjuanhdez, 06/2022 |
|||
dim matrix (3, 4) |
|||
matrix(1, 1) = 1 : matrix(1, 2) = 2 : matrix(1, 3) = -1 : matrix(1, 4) = -4 |
|||
matrix(2, 1) = 2 : matrix(2, 2) = 3 : matrix(2, 3) = -1 : matrix(2, 4) = -11 |
|||
matrix(3, 1) = -2 : matrix(3, 2) = 0 : matrix(3, 3) = -3 : matrix(3, 4) = 22 |
|||
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 |
|||
sub RREF(x()) |
|||
local nrows, ncols, lead, r, i, j, n |
|||
nrows = arraysize(matrix(), 1) //3 |
|||
ncols = arraysize(matrix(), 2) //4 |
|||
lead = 1 |
|||
for r = 1 to nrows |
|||
if lead >= ncols break |
|||
i = r |
|||
while matrix(i, lead) = 0 |
|||
i = i + 1 |
|||
if i = nrows then |
|||
i = r |
|||
lead = lead + 1 |
|||
if lead = ncols break 2 |
|||
end if |
|||
wend |
|||
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 <> 0 then |
|||
for j = 1 to ncols |
|||
matrix(r, j) = 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(i, j) - matrix(r, j) * n |
|||
next |
|||
end if |
|||
next |
|||
lead = lead + 1 |
|||
next |
|||
end sub</lang> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |