Converts lower Cholesky factors into corresponding full matrices. This applies across dimensions 3 and 4 and so is appropriate to use on sets of Cholesky factors, such as those returned by Monte-Carlo tests, where the third dimension represents the sample index and the fourth is the run index.
C | Lower Cholesky factor(s) with dimensions |
---|---|
nr | Dimension of the upper-left submatrix to be returned (default is n) |
P | Reconstructed matrix(or matrices) with dimensions |
---|
Let's create an initial covariance matrix.
P = randcov(3)
P =
0.5052 -0.2311 -0.2059
-0.2311 0.5124 -0.0714
-0.2059 -0.0714 0.7502
Now we calculate the lower Cholesky factor.
C = sqrtpsdm(P, 'lower');
We can manually construct the covariance or use lcf2mat
.
C * C.'
lcf2mat(C)
ans =
0.5052 -0.2311 -0.2059
-0.2311 0.5124 -0.0714
-0.2059 -0.0714 0.7502
ans =
0.5052 -0.2311 -0.2059
-0.2311 0.5124 -0.0714
-0.2059 -0.0714 0.7502
Sometimes, for efficiency, we need to return only the top n
-by-n
submatrix of matrix that is reconstructed from the lower Cholesky factor.
We can do this with the second argument.
P = randcov(5);
C = sqrtpsdm(P, 'lower');
P(1:3, 1:3)
lcf2mat(C, 3)
ans =
0.6846 -0.1233 -0.0311
-0.1233 0.4337 0.1801
-0.0311 0.1801 0.5882
ans =
0.6846 -0.1233 -0.0311
-0.1233 0.4337 0.1801
-0.0311 0.1801 0.5882
Let's create covariance matrices for each of 10 samples on each of 5 runs to mimic results we might obtain from a Monte-Carlo test.
P = zeros(3, 3, 10, 5);
C = zeros(3, 3, 10, 5);
for s = 1:10
for r = 1:5
P(:, :, s, r) = randcov(3);
C(:, :, s, r) = sqrtpsdm(P(:, :, s, r), 'lower');
end
end
Let's show that we can reconstruct the covariance matrices from the various lower Cholesky factors all at once and compare those results to the original covariance matrices.
P2 = lcf2mat(C);
max(abs(P(:) - P2(:)))
ans =
1.1102e-16
sqrtpsdm, ldfactor.m, udfactor.m
*kf
v1.0.3