trunk dynare_solve.m:
* fail if solve_algo=0 and we don't have the optimization toolbox (or under Octave); the previous behavior was to fallback on solve_algo=1 * fail if solve_algo is not between 0 and 4 git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2090 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
ae68da82ff
commit
d4e2d6c27f
|
@ -38,30 +38,28 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
|
|||
options_ = set_default_option(options_,'solve_algo',2);
|
||||
info = 0;
|
||||
if options_.solve_algo == 0
|
||||
if ~isempty(which('fsolve'))
|
||||
options=optimset('fsolve');
|
||||
options.MaxFunEvals = 50000;
|
||||
options.MaxIter = 2000;
|
||||
options.TolFun=1e-8;
|
||||
options.Display = 'iter';
|
||||
if jacobian_flag
|
||||
options.Jacobian = 'on';
|
||||
else
|
||||
options.Jacobian = 'off';
|
||||
end
|
||||
[x,fval,exitval,output] = fsolve(func,x,options,varargin{:});
|
||||
if exitval > 0
|
||||
info = 0;
|
||||
else
|
||||
info = 1;
|
||||
end
|
||||
return
|
||||
else
|
||||
options_.solve_algo = 1;
|
||||
if exist('OCTAVE_VERSION') || isempty(ver('optim'))
|
||||
% Note that fsolve() exists under Octave, but has a different syntax
|
||||
% So we fail for the moment under Octave, until we add the corresponding code
|
||||
error('DYNARE_SOLVE: you can''t use solve_algo=0 since you don''t have Matlab''s Optimization Toolbox')
|
||||
end
|
||||
end
|
||||
|
||||
if options_.solve_algo == 1
|
||||
options=optimset('fsolve');
|
||||
options.MaxFunEvals = 50000;
|
||||
options.MaxIter = 2000;
|
||||
options.TolFun=1e-8;
|
||||
options.Display = 'iter';
|
||||
if jacobian_flag
|
||||
options.Jacobian = 'on';
|
||||
else
|
||||
options.Jacobian = 'off';
|
||||
end
|
||||
[x,fval,exitval,output] = fsolve(func,x,options,varargin{:});
|
||||
if exitval > 0
|
||||
info = 0;
|
||||
else
|
||||
info = 1;
|
||||
end
|
||||
elseif options_.solve_algo == 1
|
||||
nn = size(x,1);
|
||||
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,varargin{:});
|
||||
elseif options_.solve_algo == 2 || options_.solve_algo == 4
|
||||
|
@ -84,8 +82,6 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
|
|||
error('exiting ...')
|
||||
end
|
||||
|
||||
% f = 0.5*fvec'*fvec ;
|
||||
|
||||
if max(abs(fvec)) < tolf
|
||||
return ;
|
||||
end
|
||||
|
@ -132,10 +128,7 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
|
|||
[x,info] = csolve(func,x,func,1e-6,500,varargin{:});
|
||||
else
|
||||
[x,info] = csolve(func,x,[],1e-6,500,varargin{:});
|
||||
end
|
||||
end
|
||||
else
|
||||
error('DYNARE_SOLVE: option solve_algo must be one of [0,1,2,3,4]')
|
||||
end
|
||||
% fvec1 = feval(func,x,varargin{:})
|
||||
|
||||
% 08/28/03 MJ add a final call to solve1 for solve_algo == 1 in case
|
||||
% initvals generates 'false' zeros in the Jacobian
|
||||
|
Loading…
Reference in New Issue