mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-13 08:50:53 +01:00
17 lines
541 B
Matlab
17 lines
541 B
Matlab
% solves system with triangular matrix
|
|
function result = backSubstitution(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
|