comparison scripts/sparse/bicg.m @ 13796:53674ceb9133

maint: fix function definition in test * bicg.m: Use function block to define funciton for test.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Nov 2011 23:28:22 -0400
parents e81ddf9cacd5
children 9cae456085c2
comparison
equal deleted inserted replaced
13794:5b395217ccb9 13796:53674ceb9133
220 %! M1 = spdiags ([ones(n,1)/(-2) ones(n,1)],-1:0, n, n); 220 %! M1 = spdiags ([ones(n,1)/(-2) ones(n,1)],-1:0, n, n);
221 %! M2 = spdiags ([4*ones(n,1) -ones(n,1)], 0:1, n, n); 221 %! M2 = spdiags ([4*ones(n,1) -ones(n,1)], 0:1, n, n);
222 %! [x, flag, relres, iter, resvec] = bicg (A, b, tol, maxit, M1, M2); 222 %! [x, flag, relres, iter, resvec] = bicg (A, b, tol, maxit, M1, M2);
223 %! assert (x, ones (size (b)), 1e-7); 223 %! assert (x, ones (size (b)), 1e-7);
224 %! 224 %!
225
226 %!function y = afun (x, t, a)
227 %! switch t
228 %! case "notransp"
229 %! y = a * x;
230 %! case "transp"
231 %! y = a' * x;
232 %! endswitch
233 %!endfunction
234 %!
225 %!test 235 %!test
226 %! n = 100; 236 %! n = 100;
227 %! A = spdiags ([-2*ones(n,1) 4*ones(n,1) -ones(n,1)], -1:1, n, n); 237 %! A = spdiags ([-2*ones(n,1) 4*ones(n,1) -ones(n,1)], -1:1, n, n);
228 %! b = sum (A, 2); 238 %! b = sum (A, 2);
229 %! tol = 1e-8; 239 %! tol = 1e-8;
230 %! maxit = 15; 240 %! maxit = 15;
231 %! M1 = spdiags ([ones(n,1)/(-2) ones(n,1)],-1:0, n, n); 241 %! M1 = spdiags ([ones(n,1)/(-2) ones(n,1)],-1:0, n, n);
232 %! M2 = spdiags ([4*ones(n,1) -ones(n,1)], 0:1, n, n); 242 %! M2 = spdiags ([4*ones(n,1) -ones(n,1)], 0:1, n, n);
233 %! 243 %!
234 %! function y = afun (x, t, a)
235 %! switch t
236 %! case "notransp"
237 %! y = a * x;
238 %! case "transp"
239 %! y = a' * x;
240 %! endswitch
241 %! endfunction
242 %!
243 %! [x, flag, relres, iter, resvec] = bicg (@(x, t) afun (x, t, A), 244 %! [x, flag, relres, iter, resvec] = bicg (@(x, t) afun (x, t, A),
244 %! b, tol, maxit, M1, M2); 245 %! b, tol, maxit, M1, M2);
245 %! assert (x, ones (size (b)), 1e-7); 246 %! assert (x, ones (size (b)), 1e-7);
246 247
247 %!test 248 %!test