Home > matlab > bicgstab_.m

bicgstab_

PURPOSE ^

Copyright (C) 2007-2011 Dynare Team

SYNOPSIS ^

function [x,status]=bicgstab_(func,b,x,tole,kmax,varargin)

DESCRIPTION ^

 Copyright (C) 2007-2011 Dynare Team

 This file is part of Dynare.

 Dynare is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 Dynare is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,status]=bicgstab_(func,b,x,tole,kmax,varargin)
0002 
0003 % Copyright (C) 2007-2011 Dynare Team
0004 %
0005 % This file is part of Dynare.
0006 %
0007 % Dynare is free software: you can redistribute it and/or modify
0008 % it under the terms of the GNU General Public License as published by
0009 % the Free Software Foundation, either version 3 of the License, or
0010 % (at your option) any later version.
0011 %
0012 % Dynare is distributed in the hope that it will be useful,
0013 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 % GNU General Public License for more details.
0016 %
0017 % You should have received a copy of the GNU General Public License
0018 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0019 
0020 status = 0;
0021 r=b-feval(func,x,varargin{:});
0022 rh_0 = r;
0023 rh = r;
0024 rho_0 = 1;
0025 alpha = 1;
0026 w = 1;
0027 v = 0;
0028 p = 0;
0029 k = 0;
0030 rho_1 = rh_0'*r;
0031 tolr = tole*norm(b);
0032 
0033 while norm(r) > tolr && k < kmax
0034     k = k+1;
0035     beta = (rho_1/rho_0)*(alpha/w);
0036     p = r+beta*(p-w*v);
0037     v = feval(func,p,varargin{:});
0038     alpha = rho_1/(rh_0'*v);
0039     r = r-alpha*v;
0040     t = feval(func,r,varargin{:});
0041     w = (t'*r)/(t'*t);
0042     rho_0 = rho_1;
0043     rho_1 = -w*(rh_0'*t);
0044     x = x+alpha*p+w*r;
0045     r = r-w*t;
0046 end
0047 if k == kmax
0048     status = 1;
0049     warning(sprintf('BICSTABN didn''t converge after %d iterations: norm(r) = %g',kmax,norm(r)));
0050 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005