2021-03-21 19:45:18 +01:00
|
|
|
function A = Alg1(A)
|
2021-03-14 18:40:53 +01:00
|
|
|
% Algorithm 1: Outer Product Gaussian Elimination
|
2021-03-13 20:23:23 +01:00
|
|
|
% Performs a gaussian eliminaion on a square matrix A.
|
2021-03-13 17:46:26 +01:00
|
|
|
|
2021-03-14 18:40:53 +01:00
|
|
|
[m, n] = size(A);
|
2021-03-13 20:23:23 +01:00
|
|
|
|
2021-03-14 18:40:53 +01:00
|
|
|
if m ~= n
|
|
|
|
error('Matrix is not square!')
|
|
|
|
end
|
|
|
|
|
|
|
|
for k = 1:n-1
|
|
|
|
if det(A(1:k, 1:k)) < eps
|
|
|
|
error('Matrix is not nonsingular!')
|
2021-03-13 20:23:23 +01:00
|
|
|
end
|
2021-03-14 18:40:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
% The following algorithm is based on the Algrotihm 3.2.1 from [2].
|
|
|
|
|
|
|
|
for k = 1 : m-1
|
|
|
|
rows = k + 1 : m;
|
|
|
|
A(rows, k) = A(rows, k)/A(k, k);
|
|
|
|
A(rows, rows) = A(rows, rows) - A(rows, k) * A(k, rows);
|
|
|
|
end
|
2021-03-13 13:42:56 +01:00
|
|
|
|
2021-03-21 19:45:18 +01:00
|
|
|
end
|
|
|
|
|