Refactored functions from 1 to 5

This commit is contained in:
Sergiusz Warga 2021-03-13 13:42:56 +01:00
parent 302dc37f78
commit 41b7057eab
6 changed files with 16 additions and 12 deletions

View File

@ -1,5 +1,5 @@
% Algorithm 1: Outer Product Gaussian Elimination (Alg. 3.2.1)
function A = outer_product_gaussian_elimination(A)
function A = Alg1_outer_product_gaussian_elimination(A)
[n, m] = size(A);
if n ~= m
@ -15,3 +15,5 @@ end
A(rows, k) = A(rows, k)/A(k, k);
A(rows, rows) = A(rows, rows) - A(rows, k) * A(k, rows);
end
end

View File

@ -1,4 +1,4 @@
function [P, Q, L, U] = gaussian_elimination_with_complete_pivoting(A)
function [P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A)
[n, m] = size(A);
if n ~= m

View File

@ -1,5 +1,5 @@
% Algorithm 3: Forward Substitution (Alg. 3.1.1)
function b = forward_substitution(L, b)
function b = Alg3_forward_substitution(L, b)
[n, m] = size(L);
if n ~= m

View File

@ -1,5 +1,5 @@
% Argorithm 4: Back Substitution (Alg. 3.1.2)
function b = back_substitution(U,b)
function b = Alg4_back_substitution(U,b)
[n, m] = size(U);
if n ~= m

View File

@ -1,6 +1,6 @@
% Algorithm 5: Gauss-Jordan Elimination
% Algorithm 5: Gauss-Jordan Elimination (Alg.
% Argument A is an augmented matrix
function A = gauss_jordan_elimination(A)
function A = Alg5_gauss_jordan_elimination(A)
% M rows, N columns

View File

@ -7,7 +7,7 @@ A = [2, -1, 0, 0;
b = [0;0;0;5];
B = outer_product_gaussian_elimination(A);
B = Alg1_outer_product_gaussian_elimination(A);
U = triu(B);
L = tril(B, -1);
x = back_substitution(U, b);
@ -23,7 +23,7 @@ b = [0;0;0;5];
B = gauss_jordan_elimination([A b])
[P, Q, L, U] = gaussian_elimination_with_complete_pivoting(A);
[P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A);
b = P*b;
% Ly = b and Ux = y
@ -40,7 +40,7 @@ A = [1, 1, 1;
b = [1;2;1];
[P, Q, L, U] = gaussian_elimination_with_complete_pivoting(A);
[P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A);
b = P*b;
% Ly = b and Ux = y
@ -69,7 +69,7 @@ A = [2, 1, 2;
1, 2, 3;
4, 1, 2];
[P, Q, L, U] = gaussian_elimination_with_complete_pivoting(A);
[P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A);
I = P*eye(3);
% Ly = b and Ux = y
@ -77,3 +77,5 @@ y = forward_substitution(L, I);
X = Q*back_substitution(U, y)
inv(A)
%% Problem 6