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

21 lines
363 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.

function A = Alg5_gauss_jordan_elimination(A)
% Algorithm 5: Gauss-Jordan Elimination
% Argument A is an augmented matrix
% M rows, N columns
[M, N] = size(A);
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
end