dynare/tests/bgp/solow-1/checkjacobian.mod

60 lines
1.5 KiB
Modula-2

// This mod file test the bgp.write function by characterizing the Balanced Growth Path of the Solow model. This is done 10000 times in a Monte Carlo loop
// randomizing the initial guess of the nonlinear solver.
var Efficiency
EfficiencyGrowth
Population
PopulationGrowth
Output
PhysicalCapitalStock ;
varexo e_x
e_n ;
parameters alpha
delta
s
rho_x
rho_n
EfficiencyGrowth_ss
PopulationGrowth_ss ;
alpha = .33;
delta = .02;
s = .20;
rho_x = .90;
rho_n = .95;
EfficiencyGrowth_ss = 1.01;
PopulationGrowth_ss = 1.01;
model(use_dll);
Efficiency = EfficiencyGrowth*Efficiency(-1);
EfficiencyGrowth/EfficiencyGrowth_ss = (EfficiencyGrowth(-1)/EfficiencyGrowth_ss)^(rho_x)*exp(e_x);
Population = PopulationGrowth*Population(-1);
PopulationGrowth/PopulationGrowth_ss = (PopulationGrowth(-1)/PopulationGrowth_ss)^(rho_n)*exp(e_n);
Output = PhysicalCapitalStock(-1)^alpha*(Efficiency*Population)^(1-alpha);
PhysicalCapitalStock = (1-delta)*PhysicalCapitalStock(-1) + s*Output;
end;
verbatim;
bgp.write(M_);
MC = 1000;
maxabsdiff = 0;
for i=1:MC
y = randi([10,1000])+(rand(6,1)-.5)*.2;
y(2) = 1+.05*rand;
y(3) = 1+.05*rand;
G = 1.01*ones(6,1)+.05*randn(6,1);
jacobian = fjaco(@checkjacobian.bgpfun, [y;G]);
[Residuals, Jacobian] = checkjacobian.bgpfun([y;G]);
maxabsdiff = max(0, max(abs(jacobian(:)-Jacobian(:))));
end
assert(maxabsdiff<1e-6, 'Analytical jacobian is wrong.')
end;