WUT_Computer_Science/ENUME/references/ENUME_ProjectA_No31/task 3/decomposeLDU.m
2021-11-10 13:12:25 +01:00

28 lines
393 B
Matlab

function [L,D,U] = decomposeLDU(A)
%DECOMPOSELDU decomposes the matrix A into L+D+U
% returns L - lowerdiagonal, D - diagonal, U - upperdiagonal
n = size(A);
L = zeros(n);
D = zeros(n);
U = zeros(n);
for i = 2:1:n
for j = 1:1:i-1
L(i,j) = A(i,j);
end
end
for i = 1:1:n
D(i,i) = A(i,i);
end
for i = 1:1:n
for j = i+1:1:n
U(i,j) = A(i,j);
end
end
end