2021-03-13 13:42:56 +01:00
|
|
|
function A = Alg5_gauss_jordan_elimination(A)
|
2021-03-13 16:16:01 +01:00
|
|
|
% Algorithm 5: Gauss-Jordan Elimination
|
|
|
|
% Argument A is an augmented matrix
|
2021-03-06 20:58:52 +01:00
|
|
|
|
2021-03-13 20:23:23 +01:00
|
|
|
[m, n] = size(A);
|
2021-03-07 22:56:18 +01:00
|
|
|
|
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-07 22:56:18 +01:00
|
|
|
|
2021-03-13 20:23:23 +01:00
|
|
|
for i = 1 : m
|
|
|
|
if i ~= k
|
|
|
|
A(i, :) = A(i, :)-(A(i, k))*row;
|
2021-03-07 22:56:18 +01:00
|
|
|
end
|
2021-03-06 20:58:52 +01:00
|
|
|
end
|
2021-03-13 16:16:01 +01:00
|
|
|
end
|
2021-03-06 20:58:52 +01:00
|
|
|
end
|