diff scripts/sparse/bicgstab.m @ 9278:2b35cb600d50

improve bicgstab and cgs
author Radek Salac <salac.r@gmail.com>
date Thu, 28 May 2009 07:03:11 +0200
parents eb63fbe60fab
children 1673a0dc019f
line wrap: on
line diff
--- a/scripts/sparse/bicgstab.m	Wed May 27 13:06:38 2009 -0700
+++ b/scripts/sparse/bicgstab.m	Thu May 28 07:03:11 2009 +0200
@@ -1,4 +1,4 @@
-## Copyright (C) 2008, 2009 Radek Salac
+## Copyright (C) 2008 Radek Salac
 ##
 ## This file is part of Octave.
 ##
@@ -84,20 +84,10 @@
     endif 
   endif
 
-  if (nargin > 4 && isnumeric (precon))
-    ## Precon can by also function.
-    if (det (precon) != 0) 
-      ## We can compute inverse preconditioner and use quicker algorithm.
-      precon = inv (precon);
-    else
-      error ("bicgstab: preconditioner is ill conditioned");
-    endif
+  if (nargin > 4 && isnumeric(precon) )
+    precon = inv(precon);
+  endif
 
-    if (isinf (cond (precon))); 
-      ## We must make test if preconditioner isn't ill conditioned.
-      error ("bicgstab: preconditioner is ill conditioned");
-    endif
-  endif
 
   ## specifies initial estimate x0
   if (nargin < 7)
@@ -112,7 +102,7 @@
   rr = res;
 
   ## Vector of the residual norms for each iteration.
-  resvec = [norm(res)];
+  resvec = [norm(res)/norm_b];
 
   ## Default behaviour we don't reach tolerance tol within maxit iterations.
   flag = 1;
@@ -169,6 +159,23 @@
     endif
   endfor
 
+  if (nargout < 2)
+    if (flag == 0) 
+      printf (["bicgstab converged at iteration %i ",
+      "to a solution with relative residual %e\n"],iter,relres);
+    elseif (flag == 3)
+      printf (["bicgstab stopped at iteration %i ",
+      "without converging to the desired tolerance %e\n",
+      "because the method stagnated.\n",
+      "The iterate returned (number %i) has relative residual %e\n"],iter,tol,iter,relres);
+    else
+      printf (["bicgstab stopped at iteration %i ",
+      "without converging to the desired toleranc %e\n",
+      "because the maximum number of iterations was reached.\n",
+      "The iterate returned (number %i) has relative residual %e\n"],iter,tol,iter,relres);
+    endif
+  endif
+
 endfunction
 
 %!demo