1function test21 2%TEST21 test cs_updown, chol_updown2 3% 4% Example: 5% test21 6% See also: testall 7 8% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com 9 10clear functions 11rand ('state', 0) ; 12randn ('state', 0) ; 13 14clf 15 16for trials = 1:100 17 if (trials <= 1) 18 n = trials ; 19 else 20 n = 1+fix (100 * rand (1)) ; 21 end 22 fprintf ('n: %d\n', n) ; 23 d = 0.1 * rand (1) ; 24 A = sprandn (n,n,d) ; 25 26 if (~ispc) 27 if (rand ( ) > .5) 28 A = A + 1i * sprand (A) ; 29 end 30 end 31 32 A = A+A' + 100 * speye (n) ; 33 try 34 p = amd (A) ; 35 catch 36 p = symamd (A) ; 37 end 38 A = sparse (A (p,p)) ; 39 40 try 41 L = chol (A)' ; 42 catch 43 continue ; 44 end 45 46 parent = etree (A) ; 47 48 subplot (1,3,1) ; 49 spy (A) ; 50 51 if (n > 0) 52 subplot (1,3,2) ; 53 treeplot (parent) ; 54 end 55 56 subplot (1,3,3) ; 57 spy (L) ; 58 59 drawnow 60 61 for trials2 = 1:10 62 63 k = 1+fix (n * rand (1)) ; 64 if (k <= 0 | k > n) %#ok 65 k = 1 ; 66 end 67 68 w = sprandn (L (:,k)) ; 69 Anew = A + w*w' ; 70 71 Lnew = cs_updown (L, w, parent) ; 72 err6 = norm (Lnew*Lnew' - Anew, 1) ; 73 74 Lnew = cs_updown (L, w, parent, '+') ; 75 err7 = norm (Lnew*Lnew' - Anew, 1) ; 76 77 [Lnew, wnew] = chol_updown2 (L, 1, w) ; 78 err2 = norm (Lnew*Lnew' - Anew, 1) ; 79 err10 = norm (wnew - (L\w)) ; 80 81 L3 = chol_updown2 (L, +1, w) ; 82 err9 = norm (L3*L3' - Anew, 1) ; 83 84 85 86 [L2, wnew] = chol_updown2 (Lnew, -1, w) ; 87 err3 = norm (L2*L2' - A, 1) ; 88 err11 = norm (wnew - (Lnew\w)) ; 89 90 L2 = cs_updown (Lnew, w, parent, '-') ; 91 err5 = norm (L2*L2' - A, 1) ; 92 93 L2 = chol_updown2 (Lnew, -1, w) ; 94 err8 = norm (L2*L2' - A, 1) ; 95 96 err = max ([err2 err3 err5 err6 err7 err9 err8 err10 err11]) ; 97 98 fprintf (' k %3d %6.2e\n', k, err) ; 99 100 if (err > 1e-11) 101 err2 %#ok 102 err3 %#ok 103 err5 %#ok 104 err6 %#ok 105 err7 %#ok 106 err8 %#ok 107 err9 %#ok 108 err10 %#ok 109 err11 %#ok 110 pause 111 end 112 113 114 end 115 % pause 116 117end 118