Introduced outer_product_gaussian_elimination() and back_substitution()

This commit is contained in:
Sergiusz Warga 2021-03-06 14:15:22 +01:00
parent e2a9a9425c
commit 2b47852870
3 changed files with 38 additions and 6 deletions

View File

@ -0,0 +1,21 @@
function back_substitution(U,b)
[n, m] = size(U);
if n ~= m
error('Matrix is not squared!')
end
if length(b) ~= n
error('Vector b has wrong length!')
end
if det(A) == 0
error('Matrix is not nonsingular!')
end
b(n) = b(n)/U(n, n)
for i = n-1:-1:n
end
end

View File

@ -0,0 +1,8 @@
clear all;
B = [2, -1, 0, 0; -1, 2, -1, 0;0, -1, 2, -1; 0, 0, -1, 2]
b = [0;0;0;5]
[U, Mk] = outer_product_gaussian_elimination(B)
back_substitution(U, b)

View File

@ -1,5 +1,5 @@
% Outer Product Gaussian Elimination (Alg. 3.2.1) % Outer Product Gaussian Elimination (Alg. 3.2.1)
function outer_product_gaussian_elimination(A) function U, Mk = outer_product_gaussian_elimination(A)
[n, m] = size(A); [n, m] = size(A);
if n ~= m if n ~= m
@ -13,8 +13,11 @@ end
A A
for k = 1 : n-1 for k = 1 : n-1
k rows = k + 1 : n;
rows = k + 1 : n A(rows, k) = A(rows, k)/A(k, k);
A(rows, k) = A(rows, k)/A(k, k) A(rows, rows) = A(rows, rows) - A(rows, k) * A(k, rows);
A(rows, rows) = A(rows, rows) - A(rows, k) * A(k, rows) A
end end
U = triu(A)
Mk = diag(A,-1) % Gauss vector