AAE-NA-Labs/01_Direct-Methods-for-Solving-Linear-Systems/Code/Alg5.m

21 lines
391 B
Mathematica
Raw Normal View History

2021-03-21 19:45:18 +01:00
function A = Alg5(A)
2021-03-13 16:16:01 +01:00
% Algorithm 5: Gauss-Jordan Elimination
2021-03-14 18:40:53 +01:00
% A = Alg5_gauss_jordan_elimination(A) performs Gauss-Jordan elimination
% on an augmented matrix A.
2021-03-06 20:58:52 +01:00
2021-03-21 19:45:18 +01:00
[m, ~] = size(A);
2021-03-13 20:23:23 +01:00
for k = 1 : m
2021-03-13 13:33:13 +01:00
2021-03-13 20:23:23 +01:00
row = A(k, :);
row = row/row(k);
A(k, :) = row;
2021-03-13 20:23:23 +01:00
for i = 1 : m
2021-03-21 19:45:18 +01:00
if i ~= k && A(i, k) ~= 0
2021-03-13 20:23:23 +01:00
A(i, :) = A(i, :)-(A(i, k))*row;
end
2021-03-06 20:58:52 +01:00
end
2021-03-13 16:16:01 +01:00
end
2021-03-14 18:40:53 +01:00
2021-03-06 20:58:52 +01:00
end