From 302dc37f7867173998934610ad96dafbc2f2d852 Mon Sep 17 00:00:00 2001 From: EdwardEisenhauer Date: Sat, 13 Mar 2021 13:33:13 +0100 Subject: [PATCH] Modified Algorithm 5 --- .../gauss_jordan_elimination.m | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Direct Methods for Solving Linear Systems/gauss_jordan_elimination.m b/Direct Methods for Solving Linear Systems/gauss_jordan_elimination.m index d7bf51c..09c63bc 100644 --- a/Direct Methods for Solving Linear Systems/gauss_jordan_elimination.m +++ b/Direct Methods for Solving Linear Systems/gauss_jordan_elimination.m @@ -1,25 +1,28 @@ % Algorithm 5: Gauss-Jordan Elimination -% Input A is an augmented matrix +% Argument A is an augmented matrix function A = gauss_jordan_elimination(A) -[n, m] = size(A); +% M – rows, N – columns -if n + 1 ~= m - error('Matrix is not squared!') -end - +[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 k = 1 : m-1 +for m = 1 : M - row = A(k, :); - row = row/row(k); - A(k, :) = row; - for l = 1 : m-1 - if l ~= k - A(l, :) = A(l, :)-(A(l, k))*row; + 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 \ No newline at end of file