% LU-factorization

A=rand(3)
[L1,U]=lu(A)
[L2,U,P]=lu(A)

%

P'
L1
L2
P'*L1 %L2
P*L2 %L1

%

%check A=L1*U
A-L1*U
%check A=P'*L2*U
A-P'*L2*U

%

A=A*A'
U=chol(A)
L=chol(A,'lower')

%

%check L=U' and U=L'
L-U',U-L'
%check A=L*U
A-L*U
%check A=L*L'and A=U'*U
A-L*L', A-U'*U

%
% For non-symmetric matrix it's not a factorization

A1=[3 2;1 4],A2=[2 0; 2 2]
A=blkdiag(A1,A2) %non-symmetric, A<>A'
eig(A)
U=chol(A)
%A=U'*U
A-U'*U