1classdef factorization_qrt_dense < factorization
2%FACTORIZATION_QRT_DENSE A' = Q*R where A is full.
3
4% Copyright 2011-2012, Timothy A. Davis, http://www.suitesparse.com
5
6    methods
7
8        function F = factorization_qrt_dense (A, fail_if_singular)
9            %FACTORIZATION_QRT_DENSE : A' = Q*R
10            [m, n] = size (A) ;
11            if (m > n)
12                error ('FACTORIZE:wrongdim', 'QR(A'') method requires m<=n.') ;
13            end
14            [f.Q, f.R] = qr (A',0) ;
15            F.A_condest = cheap_condest (get_diag (f.R), fail_if_singular) ;
16            F.A = A ;
17            F.Factors = f ;
18            F.A_rank = rank_est (f.R, m, n) ;
19            F.kind = 'dense economy QR factorization: A'' = Q*R' ;
20        end
21
22        function e = error_check (F)
23            %ERROR_CHECK : return relative 1-norm of error in factorization
24            % meant for testing only
25            f = F.Factors ;
26            e = norm (F.A' - f.Q*f.R, 1) / norm (F.A, 1) ;
27        end
28
29        function x = mldivide_subclass (F,b)
30            %MLDIVIDE_SUBCLASS x = A\b using a dense QR factorization of A'
31            % minimum 2-norm solution of an underdetermined system
32            % x = Q * (R' \ b)
33            f = F.Factors ;
34            opUT.UT = true ;
35            opUT.TRANSA = true ;
36            y = b ;
37            if (issparse (y))
38                y = full (y) ;
39            end
40            x = f.Q * linsolve (f.R, y, opUT) ;
41        end
42
43        function x = mrdivide_subclass (b,F)
44            %MRDIVIDE_SUBCLASS x = b/A using dense QR of A'
45            % least-squares solution of a overdetermined problem
46            % x = (R \ (Q' * b'))'
47            f = F.Factors ;
48            opU.UT = true ;
49            y = f.Q' * b' ;
50            if (issparse (y))
51                y = full (y) ;
52            end
53            x = linsolve (f.R, y, opU)' ;
54        end
55    end
56end
57