*kf
by An Uncommon Lab

ud2mat

Converts [U,d] from udfactor into the original matrix that the factors represent, U * diag(d) * U.', with minimal operations.

This also works with multiple sets of U and d, stored along the 3rd and 2nd dimension of each, respectively.

M = ud2mat(U, d)

Finally, this works with the compact form of UDU factorization, where d is not created explicitly and is stored on the diagonal of U.

Inputs

U

Upper unitriangular part of UDU factorization

d

Diagonals of UDU factorization

Outputs

M

Reconstructed matrix (or matrices)

Example: Basic Case

Let's generate a positive-definite matrix, factorize, and show that the factors reconstruct properly:

M = randcov(3);
[U, d] = udfactor(M);
U * diag(d) * U.'
ud2mat(U, d)
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

Example: Compact Form

We can also use ud2mat with the compact UDU decomposition to save space and time.

Z = udfactor(M);
ud2mat(Z)
ans =
    0.5052   -0.2311   -0.2059
   -0.2311    0.5124   -0.0714
   -0.2059   -0.0714    0.7502

Example: Dimensions 3 and 4

Let's generate a positive-definte matrix for each of 10 samples of each of 5 runs.

nx = 3;
ns = 10;
nr = 5;
M = zeros(nx, nx, ns, nr);
U = zeros(nx, nx, ns, nr);
d = zeros(nx, ns, nr);
for s = 1:ns
    for r = 1:nr
        M(:, :, s, r) = randcov(nx);
        [U(:, :, s, r), d(:, s, r)] = udfactor(M(:, :, s, r));
    end
end

Let's reconstruct all of the matrices in M all at once and show the difference.

M2 = ud2mat(U, d);
max(abs(M(:) - M2(:)))
ans =
   1.1102e-16

See Also

ldfactor, ld2mat, udfactor, sqrtpsdm

Table of Contents

  1. Inputs
  2. Outputs
  3. Example: Basic Case
  4. Example: Compact Form
  5. Example: Dimensions 3 and 4
  6. See Also