AAE-NA-Labs/01_Direct-Methods-for-Solving-Linear-Systems/Report/algorithms/Alg10.m

24 lines
526 B
Mathematica
Raw Permalink Normal View History

2021-03-13 21:13:03 +01:00
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.
2023-03-11 20:08:05 +01:00
% We are using Outer product Version (Golub, Load, Alg. 4.2.2), which
% computes lower triangular G, such that A = G*G^T
2021-03-13 21:13:03 +01:00
[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);
2023-03-11 20:08:05 +01:00
end