1function test4
2%TEST4 test cholmod2 with multiple and sparse right-hand-sides
3% Example:
4%   test4
5% See also cholmod_test
6
7% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com
8
9fprintf ('=================================================================\n');
10fprintf ('test4: test cholmod2 with multiple and sparse right-hand-sides\n') ;
11
12Prob = ssget ('HB/bcsstk01') ;
13A = Prob.A ;
14n = size (A,1) ;
15b = rand (n,1) ;
16x = cholmod2 (A,b) ;
17m2 = norm (A*x-b,1) ;
18b = sparse (b) ;
19x = cholmod2 (A,b) ;
20m2 = max (m2, norm (A*x-b,1)) ;
21m1 = 0 ;
22
23for nrhs = 1:80
24    b = sparse (rand (n,nrhs)) ;
25    x = A\b ;
26    e1 = norm (A*x-b,1) ;
27    x = cholmod2 (A,b) ;
28    e2 = norm (A*x-b,1) ;
29    if (e2 > 1e-11)
30	error ('!') ;
31    end
32    m1 = max (m1, e1) ;
33    m2 = max (m2, e2) ;
34end
35
36for nrhs = 1:80
37    b = sprandn (n, nrhs, 0.01) ;
38    x = A\b ;
39    % nnz (x) / (n*nrhs)
40    e1 = norm (A*x-b,1) ;
41    x = cholmod2 (A,b) ;
42    e2 = norm (A*x-b,1) ;
43    if (e2 > 1e-11)
44	error ('!') ;
45    end
46    m1 = max (m1, e1) ;
47    m2 = max (m2, e2) ;
48end
49
50fprintf ('maxerr %e %e\n', m1, m2) ;
51
52if (m1 > 1e-11 | m2 > 1e-11)						    %#ok
53    error ('!') ;
54end
55
56fprintf ('test4 passed\n') ;
57