WUT_Computer_Science/ENUME/references/szopinski-enume/projA/backsubst.m
2021-11-10 13:12:25 +01:00

21 lines
629 B
Matlab

% ENUME MICHAŁ SZOPIŃSKI
% PROJECT A NUMBER 62
% https://github.com/Lachcim/szopinski-enume
% solves system with triangular matrix
function result = backsubst(eqsys)
for col = size(eqsys, 1):-1:1
% normalize diagonal coefficients to 1
eqsys(col, :) = eqsys(col, :) / eqsys(col, col);
% eliminate factor from other rows
for row = (col - 1):-1:1
reductor = eqsys(row, col) / eqsys(col, col);
eqsys(row, :) = eqsys(row, :) - eqsys(col, :) * reductor;
end
end
% rightmost column is now the result
result = eqsys(:, size(eqsys, 2));
end