%% LDL Factorization of 3-by-3 Hermitian Positive Definite Matrix

% Copyright 2019 The MathWorks, Inc.

%%
% This example shows how to use <docid:dsp_ref#f4-2049914
% LDL Factorization> to LDL-factor a 3-by-3 Hermitian positive definite matrix.
%%
% For the input in the model, the corresponding L and D values become:
%%
L = [1     0   0; 
   -0.11   1   0;
    0.22 -0.61 1]
D = [9.00  0    0;
      0   7.89  0;
      0    0   3.66]
Ltranspose = L'

%%
% The output matrix is composed of the bottom left triangle of the |L|
% matrix, the diagonal of the |D| matrix, and the top right triangle of |Ltranspose|.
% When they are combined, the output is:
S = [D(1,1) Ltranspose(1,2), Ltranspose(1,3);
     L(2,1)  D(2,2), Ltranspose(2,3);
     L(3,1)  L(3,2), D(3,3)]
 
%%
% In the model, the output is the same.
model = "ex_ldl_factorization";
open_system(model);
sim(model);