Modified Algorithm 5
This commit is contained in:
parent
d4d323fd19
commit
302dc37f78
@ -1,25 +1,28 @@
|
|||||||
% Algorithm 5: Gauss-Jordan Elimination
|
% Algorithm 5: Gauss-Jordan Elimination
|
||||||
% Input A is an augmented matrix
|
% Argument A is an augmented matrix
|
||||||
function A = gauss_jordan_elimination(A)
|
function A = gauss_jordan_elimination(A)
|
||||||
|
|
||||||
[n, m] = size(A);
|
% M – rows, N – columns
|
||||||
|
|
||||||
if n + 1 ~= m
|
[M, N] = size(A);
|
||||||
error('Matrix is not squared!')
|
%
|
||||||
end
|
% if M + 1 ~= N
|
||||||
|
% error('Matrix is not squared!')
|
||||||
|
% end
|
||||||
|
%
|
||||||
% if det(A) == 0
|
% if det(A) == 0
|
||||||
% error('Matrix is not nonsingular!')
|
% error('Matrix is not nonsingular!')
|
||||||
% end
|
% end
|
||||||
|
|
||||||
for k = 1 : m-1
|
for m = 1 : M
|
||||||
|
|
||||||
row = A(k, :);
|
row = A(m, :);
|
||||||
row = row/row(k);
|
row = row/row(m);
|
||||||
A(k, :) = row;
|
A(m, :) = row;
|
||||||
for l = 1 : m-1
|
|
||||||
if l ~= k
|
for n = 1 : M
|
||||||
A(l, :) = A(l, :)-(A(l, k))*row;
|
if n ~= m
|
||||||
|
A(n, :) = A(n, :)-(A(n, m))*row;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user