From 8a90e7eecdb5fcba32362953dfd4eb61e81b6688 Mon Sep 17 00:00:00 2001 From: EdwardEisenhauer Date: Sat, 13 Mar 2021 21:13:03 +0100 Subject: [PATCH] Added Algorithm 10 --- .../Alg10.m | 24 +++++++++++++++++++ .../Alg3_forward_substitution.m | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Direct Methods for Solving Linear Systems/Alg10.m diff --git a/Direct Methods for Solving Linear Systems/Alg10.m b/Direct Methods for Solving Linear Systems/Alg10.m new file mode 100644 index 0000000..44fb30b --- /dev/null +++ b/Direct Methods for Solving Linear Systems/Alg10.m @@ -0,0 +1,24 @@ +function A = Alg10(A) +% Algorithm 10: Cholesky (Banachiewicz) factorization. +% Matrix A has to be symmetric and positive-definite: +% all d(i, i) > 0 for A = LDL^T. +% We are using Outer product Version (Golub, Load, Alg. 4.2.2). + +[m, n] = size(A); + +if m ~= n + error('Matrix is not square!') +end + +for k = 1:m + A(k,k) = sqrt(A(k,k)); + A(k+1:n, k) = A(k+1:n, k)/A(k,k); + for j = k+1:n + A(j:n, j) = A(j:n, j) - A(j:n, k)*A(j, k); + end +end + +A = tril(A); + +end + diff --git a/Direct Methods for Solving Linear Systems/Alg3_forward_substitution.m b/Direct Methods for Solving Linear Systems/Alg3_forward_substitution.m index 472da08..a0618c0 100644 --- a/Direct Methods for Solving Linear Systems/Alg3_forward_substitution.m +++ b/Direct Methods for Solving Linear Systems/Alg3_forward_substitution.m @@ -3,7 +3,7 @@ function b = Alg3_forward_substitution(L, b) [m, n] = size(L); if m ~= n - error('Matrix is not squared!') + error('Matrix is not squar!') end if length(b) ~= m