Implement solve_algo=0 for Octave (closes #144)
parent
9d6ad96abd
commit
23ba760c3b
|
@ -1788,7 +1788,7 @@ periods 100;
|
|||
<term><option>solve_algo</option> = <replaceable>INTEGER</replaceable></term>
|
||||
<listitem><para>Determines the non-linear solver to use. Possible values for the option are:
|
||||
<itemizedlist>
|
||||
<listitem><para><literal>0</literal>: uses <trademark class="registered">MATLAB</trademark> Optimization Toolbox FSOLVE (not available under Octave)</para></listitem>
|
||||
<listitem><para><literal>0</literal>: uses <literal>fsolve</literal> (under <trademark class="registered">MATLAB</trademark>, only available if you have the Optimization Toolbox; always available under Octave)</para></listitem>
|
||||
<listitem><para><literal>1</literal>: uses Dynare's own nonlinear equation solver</para></listitem>
|
||||
<listitem><para><literal>2</literal>: splits the model into recursive blocks and solves each block in turn</para></listitem>
|
||||
<listitem><para><literal>3</literal>: Chris Sims' solver</para></listitem>
|
||||
|
|
|
@ -38,10 +38,8 @@ global options_
|
|||
options_ = set_default_option(options_,'solve_algo',2);
|
||||
info = 0;
|
||||
if options_.solve_algo == 0
|
||||
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')
|
||||
if ~exist('OCTAVE_VERSION') && isempty(ver('optim'))
|
||||
error('You can''t use solve_algo=0 since you don''t have MATLAB''s Optimization Toolbox')
|
||||
end
|
||||
options=optimset('fsolve');
|
||||
options.MaxFunEvals = 50000;
|
||||
|
@ -53,7 +51,15 @@ if options_.solve_algo == 0
|
|||
else
|
||||
options.Jacobian = 'off';
|
||||
end
|
||||
[x,fval,exitval,output] = fsolve(func,x,options,varargin{:});
|
||||
if ~exist('OCTAVE_VERSION')
|
||||
[x,fval,exitval,output] = fsolve(func,x,options,varargin{:});
|
||||
else
|
||||
% Under Octave, use a wrapper, since fsolve() does not have a 4th arg
|
||||
func2 = str2func(func);
|
||||
func = @(x) func2(x, varargin{:});
|
||||
[x,fval,exitval,output] = fsolve(func,x,options);
|
||||
end
|
||||
|
||||
if exitval > 0
|
||||
info = 0;
|
||||
else
|
||||
|
|
|
@ -28,18 +28,18 @@ putenv("GNUTERM", "dumb")
|
|||
|
||||
for block = 0:1
|
||||
for bytecode = 0:1
|
||||
## Recall that solve_algo={0,7} and stack_solve_algo=2 are not supported
|
||||
## Recall that solve_algo=7 and stack_solve_algo=2 are not supported
|
||||
## under Octave
|
||||
default_solve_algo = 2;
|
||||
default_stack_solve_algo = 0;
|
||||
if !block && !bytecode
|
||||
solve_algos = 1:4;
|
||||
solve_algos = 0:4;
|
||||
stack_solve_algos = 0;
|
||||
elseif block && !bytecode
|
||||
solve_algos = [1:4 6 8];
|
||||
solve_algos = [0:4 6 8];
|
||||
stack_solve_algos = [0 1 3 4];
|
||||
else
|
||||
solve_algos = [1:6 8];
|
||||
solve_algos = [0:6 8];
|
||||
stack_solve_algos = [0 1 3:5];
|
||||
endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue