1function [x1,x2,e1,e2] = testsolve (A,b) 2%TESTSOLVE test CHOLMOD and compare with x=A\b 3% [x1,x2,e1,e2] = testsolve (A,b) ; 4% Compare CHOLMOD and MATLAB's x=A\b 5% x1 = A\b, x2 = cholmod2(A,b), e1 = norm(A*x1-b), e2 = norm(A*x2-b) 6% Example: 7% [x1,x2,e1,e2] = testsolve (A,b) ; 8% See also cholmod_test 9 10% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com 11 12fprintf ('A: [n %6d real %d] B: [sp:%d nrhs %d real %d] ', ... 13 size(A,1), isreal(A), issparse(b), size(b,2), isreal(b)) ; 14tic 15x1 = A\b ; 16t1 = toc ; 17tic 18x2 = cholmod2(A,b) ; 19t2 = toc ; 20tic 21e1 = norm (A*x1-b,1) ; 22t3 = toc ; 23e2 = norm (A*x2-b,1) ; 24if (e2 == 0 | e1 == 0) %#ok 25 e12 = 0 ; 26else 27 e12 = log2 (e1/e2) ; 28end 29if (t2 == 0) 30 t12 = 1 ; 31else 32 t12 = t1 / t2 ; 33end 34if (t2 == 0) 35 t32 = 1 ; %#ok 36else 37 t32 = t3 / t2 ; %#ok 38end 39fprintf (' [e1: %5.0e : %5.1f] [t1: %8.2f t2 %8.2f : %5.1f]\n', ... 40 e1, e12, t1, t2, t12) ; 41if (e2 > max (1e-8, 1e3*e1)) 42 error ('!') ; 43end 44