AAE-NA-Labs/Direct Methods for Solving Linear Systems/gauss_jordan_elimination.m

28 lines
490 B
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

% Algorithm 5: Gauss-Jordan Elimination
% Argument A is an augmented matrix
function A = gauss_jordan_elimination(A)
% M rows, N columns
[M, N] = size(A);
%
% if M + 1 ~= N
% error('Matrix is not squared!')
% end
%
% if det(A) == 0
% error('Matrix is not nonsingular!')
% end
for m = 1 : M
row = A(m, :);
row = row/row(m);
A(m, :) = row;
for n = 1 : M
if n ~= m
A(n, :) = A(n, :)-(A(n, m))*row;
end
end
end