1classdef factorization_lu_dense < factorization 2%FACTORIZATION_LU_DENSE A(p,:) = L*U where A is square and full. 3 4% Copyright 2011-2012, Timothy A. Davis, http://www.suitesparse.com 5 6 methods 7 8 function F = factorization_lu_dense (A, fail_if_singular) 9 %FACTORIZATION_LU_DENSE : A(p,:) = L*U 10 [m, n] = size (A) ; 11 if (m ~= n) 12 error ('FACTORIZE:wrongdim', ... 13 'LU for rectangular matrices not supported. Use QR.') ; 14 end 15 [f.L, f.U, f.p] = lu (A, 'vector') ; 16 F.A_condest = cheap_condest (get_diag (f.U), fail_if_singular) ; 17 F.A = A ; 18 F.Factors = f ; 19 F.A_rank = n ; 20 F.kind = 'dense LU factorization: A(p,:) = L*U' ; 21 end 22 23 function e = error_check (F) 24 %ERROR_CHECK : return relative 1-norm of error in factorization 25 % meant for testing only 26 f = F.Factors ; 27 e = norm (F.A (f.p,:) - f.L*f.U, 1) / norm (F.A, 1) ; 28 end 29 30 function x = mldivide_subclass (F,b) 31 %MLDIVIDE_SUBCLASS x=A\b using dense LU 32 % x = U \ (L \ (b (p,:))) ; 33 f = F.Factors ; 34 opL.LT = true ; 35 opU.UT = true ; 36 y = b (f.p, :) ; 37 if (issparse (y)) 38 y = full (y) ; 39 end 40 x = linsolve (f.U, linsolve (f.L, y, opL), opU) ; 41 end 42 43 function x = mrdivide_subclass (b,F) 44 %MRDIVIDE_SUBCLASS x = b/A using dense LU 45 % x (:,p) = (L' \ (U' \ b'))' 46 f = F.Factors ; 47 opUT.UT = true ; 48 opUT.TRANSA = true ; 49 opLT.LT = true ; 50 opLT.TRANSA = true ; 51 y = b' ; 52 if (issparse (y)) 53 y = full (y) ; 54 end 55 x = (linsolve (f.L, linsolve (f.U, y, opUT), opLT))'; 56 x (:, f.p) = x ; 57 end 58 end 59end 60