dynare_solve.m: make sure str2func is only used on strings

Otherwise, code crashes
time-shift
Johannes Pfeifer 2016-08-12 11:59:57 +02:00
parent 816b5bb884
commit 80049a6d09
1 changed files with 10 additions and 2 deletions

View File

@ -102,7 +102,11 @@ if options.solve_algo == 0
[x,fval,exitval,output] = fsolve(func,x,options4fsolve,varargin{:});
else
% Under Octave, use a wrapper, since fsolve() does not have a 4th arg
func2 = str2func(func);
if isstring(func)
func2 = str2func(func);
else
func2 = func;
end
func = @(x) func2(x, varargin{:});
% The Octave version of fsolve does not converge when it starts from the solution
fvec = feval(func,x);
@ -116,7 +120,11 @@ if options.solve_algo == 0
if exitval == 1
info = 0;
elseif exitval > 1
func2 = str2func(func);
if isstring(func)
func2 = str2func(func);
else
func2 = func;
end
func = @(x) func2(x, varargin{:});
fvec = feval(func,x);
if max(abs(fvec)) >= tolf