1function test20 2%TEST20 test chol_updown2 3% 4% Example: 5% test20 6% See also: testall 7 8% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com 9 10clear functions 11 12rand ('state', 0) ; 13maxerr = [0 0 0 0] ; 14 15for trials = 1:100 16 17 n = fix (100 * rand (1)) ; 18 A = rand (n) ; 19 20 if (~ispc) 21 if (mod (trials, 2) == 0) 22 A = A + 1i*rand(n) ; 23 end 24 end 25 26 A1 = A*A' + n*eye (n) ; 27 28 try 29 L1 = chol (A1)' ; 30 catch 31 continue ; 32 end 33 err1 = norm (L1*L1'-A1) ; 34 35 w = rand (n,1) ; 36 37 A2 = A1 + w*w' ; 38 39 L2 = chol (A2)' ; 40 err2 = norm (L2*L2'-A2) ; 41 42 % try an update 43 L2b = chol_updown2 (L1, +1, w) ; 44 err2b = norm (L2b*L2b'-A2) ; 45 46 % try a downdate 47 L1b = chol_updown2 (L2, -1, w) ; %#ok 48 err1b = norm (L1b*L1b'-A1) ; 49 50 51 fprintf ('%3d: %6.2e %6.2e : %6.2e %6.2e\n', n, err1, err2, err2b, err1b) ; 52 % pause 53 54 maxerr = max (maxerr, [err1 err2 err2b err1b]) ; 55end 56 57fprintf ('maxerr: %g\n', maxerr) ; 58