bgp-tests: Octave compatibility fixes

time-shift
Johannes Pfeifer 2020-11-19 13:41:12 +01:00
parent 68f60bc411
commit 904296738d
2 changed files with 14 additions and 5 deletions

View File

@ -62,10 +62,19 @@ end;
verbatim;
bgp.write(M_);
options = optimoptions('fsolve','Display','iter','Algorithm','levenberg-marquardt','MaxFunctionEvaluations',1000000,'MaxIterations',100000,'SpecifyObjectiveGradient',true,'FunctionTolerance',1e-6,'StepTolerance',1e-6);
y = 1+(rand(M_.endo_nbr,1)-.5)*.5;
y = 1+(rand(M_.endo_nbr,1)-.5)*.25;
g = ones(M_.endo_nbr,1);% 1+(rand(M_.endo_nbr,1)-.5)*.1;
[y, fval, exitflag] = fsolve(@fs2000.bgpfun, [y;g], options);
if ~isoctave
options = optimoptions('fsolve','Display','iter','Algorithm','levenberg-marquardt','MaxFunctionEvaluations',1000000,'MaxIterations',100000,'SpecifyObjectiveGradient',true,'FunctionTolerance',1e-6,'StepTolerance',1e-6);
[y, fval, exitflag] = fsolve(@fs2000.bgpfun, [y;g], options);
else
options = optimset('Display','iter','Algorithm','levenberg-marquardt','MaxFunEvals',1000000,'MaxIter',100000,'GradObj','on','TolFun',1e-6,'TolX',1e-6);
h=str2func('fs2000.bgpfun'); %workaround for https://savannah.gnu.org/bugs/?46659 still present in Octave 5
[y, fval, exitflag] = fsolve(h, [y;g], options);
end
if exitflag<1
error('Solution not found')
end
y(1:M_.orig_endo_nbr)
y(M_.endo_nbr+(1:M_.orig_endo_nbr))

View File

@ -17,7 +17,7 @@ verbatim;
bgp.write(M_);
if isoctave
options = optimset('Display', 'iter', 'MaxFunEvals', 1000000,'MaxIter',100000,'Jacobian','on','TolFun',1e-6,'TolX',1e-6);
options = optimset('Display', 'iter', 'MaxFunEvals', 1000000,'MaxIter',100000,'Jacobian','on','TolFun',1e-7,'TolX',1e-7);
else
options = optimoptions('fsolve','Display','iter','Algorithm','levenberg-marquardt','MaxFunctionEvaluations',1000000,'MaxIterations',100000,'SpecifyObjectiveGradient',true,'FunctionTolerance',1e-6,'StepTolerance',1e-6);
end
@ -28,7 +28,7 @@ verbatim;
else
fun = @ramsey.bgpfun;
end
y = 1+(rand(M_.endo_nbr,1)-.5)*.5;
y = 1+(rand(M_.endo_nbr,1)-.5)*.25;
g = ones(M_.endo_nbr,1);% 1+(rand(M_.endo_nbr,1)-.5)*.1;
[y, fval, exitflag] = fsolve(fun, [y;g], options);
assert(max(abs(y(M_.endo_nbr+(1:M_.orig_endo_nbr))-1.02))<1e-6)