1function test_qr 2%TEST_QR test various QR factorization methods 3% 4% Example: 5% test_qr 6% See also: testall 7 8% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com 9 10index = ssget ; 11[ignore f] = sort (max (index.nrows,index.ncols)) ; 12 13% f = 276 14% f = 706 15f = f (1:100) ; 16 17for i = f 18 19 % Prob = ssget (i,index) 20 Prob = ssget (i) ; 21 disp (Prob) ; 22 A = Prob.A ; 23 [m n] = size (A) ; 24 if (m < n) 25 A = A' ; 26 end 27 [m n] = size (A) ; 28 if (sprank (A) < n | ~isreal (A)) %#ok 29 continue ; 30 end 31 32 [V,beta,p,R1,q] = cs_qr(A) ; 33 A = A (p,q) ; 34 parent = etree (A, 'col') ; %#ok 35 36 R0 = qr (A) ; 37 R2 = qr_givens (full (A)) ; 38 R3 = qr_givens_full (full (A)) ; 39 40 subplot (2,2,1) ; cspy (R0) ; title ('matlab') ; 41 subplot (2,2,2) ; cspy (R3) ; title ('qr-full') ; 42 subplot (2,2,3) ; cspy (R2) ; title ('qr-givens') ; 43 subplot (2,2,4) ; cspy (R1) ; title ('cs-qr') ; 44 45 e0 = norm (A'*A-R0'*R0,1) / norm (A,1) ; 46 e1 = norm (A'*A-R1'*R1,1) / norm (A,1) ; 47 e2 = norm (A'*A-R2'*R2,1) / norm (A,1) ; 48 e3 = norm (A'*A-R3'*R3,1) / norm (A,1) ; 49 fprintf ('error %6.2e %6.2e %6.2e %6.2e\n', e0, e1, e2, e3) ; 50 drawnow 51 if (e0 > 0 && (e1 > e0*1e3 | e2 > e0*1e3)) %#ok 52 pause 53 end 54end 55