1classdef factorization_ldl_dense < factorization 2%FACTORIZATION_LDL_DENSE P'*A*P = L*D*L' where A is full and symmetric 3 4% Copyright 2011-2012, Timothy A. Davis, http://www.suitesparse.com 5 6 methods 7 8 function F = factorization_ldl_dense (A) 9 %FACTORIZATION_LDL_DENSE : A(p,p) = L*D*L' 10 if (isempty (A)) 11 f.L = [ ] ; 12 f.D = [ ] ; 13 f.p = [ ] ; 14 else 15 [f.L, f.D, f.p] = ldl (A, 'vector') ; 16 end 17 % D is block diagonal with 2-by-2 blocks, and is best stored as 18 % a *sparse* matrix, not full. This saves storage and speeds up 19 % D\b in the solve phases below. 20 f.D = sparse (f.D) ; 21 c = full (condest (f.D)) ; 22 if (c > 1/(2*eps)) 23 error ('MATLAB:singularMatrix', ... 24 'Matrix is singular to working precision.') ; 25 end 26 n = size (A,1) ; 27 F.A = A ; 28 F.Factors = f ; 29 F.A_rank = n ; 30 F.A_condest = c ; 31 F.kind = 'dense LDL factorization: A(p,p) = L*D*L''' ; 32 end 33 34 function e = error_check (F) 35 %ERROR_CHECK : return relative 1-norm of error in factorization 36 % meant for testing only 37 f = F.Factors ; 38 e = norm (F.A (f.p, f.p) - f.L*f.D*f.L', 1) / norm (F.A, 1) ; 39 end 40 41 function x = mldivide_subclass (F,b) 42 %MLDIVIDE_SUBCLASS x = A\b using dense LDL 43 % x = P * (L' \ (D \ (L \ (P' * b)))) 44 f = F.Factors ; 45 opL.LT = true ; 46 opLT.LT = true ; 47 opLT.TRANSA = true ; 48 y = b (f.p, :) ; 49 if (issparse (y)) 50 y = full (y) ; 51 end 52 x = linsolve (f.L, f.D \ linsolve (f.L, y, opL), opLT) ; 53 x (f.p, :) = x ; 54 end 55 56 function x = mrdivide_subclass (b,F) 57 %MRDIVIDE_SUBCLASS x = b/A using dense LDL 58 % x = (P * (L' \ (D \ (L \ (P' * b')))))' 59 x = (mldivide_subclass (F, b'))' ; 60 end 61 end 62end 63