sim1_purely_static: use the sparse representation of the dynamic file
parent
4a793f89ff
commit
5f42e84b0b
|
@ -19,14 +19,11 @@ function [endogenousvariables, info] = sim1_purely_static(endogenousvariables, e
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
if nnz(M.lead_lag_incidence(1,:)) ~= M.endo_nbr
|
||||
error('All endogenous variables must appear at the current period!')
|
||||
end
|
||||
|
||||
if ismember(options.solve_algo, [12,14])
|
||||
[funcs, feedback_vars_idxs] = setup_time_recursive_block_simul(M);
|
||||
else
|
||||
dynamicmodel = str2func(sprintf('%s.%s', M.fname, 'dynamic'));
|
||||
dynamic_resid = str2func([M.fname '.sparse.dynamic_resid']);
|
||||
dynamic_g1 = str2func([M.fname '.sparse.dynamic_g1']);
|
||||
end
|
||||
|
||||
function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T)
|
||||
|
@ -42,8 +39,8 @@ info.status = true;
|
|||
y = endogenousvariables(:,1);
|
||||
|
||||
for it = 1:options.periods
|
||||
x = exogenousvariables(it,:);
|
||||
if ismember(options.solve_algo, [12,14])
|
||||
x = exogenousvariables(it,:);
|
||||
T = NaN(M.block_structure.dyn_tmp_nbr);
|
||||
y_dynamic = [NaN(M.endo_nbr, 1); y; NaN(M.endo_nbr, 1)];
|
||||
for blk = 1:length(M.block_structure.block)
|
||||
|
@ -73,7 +70,7 @@ for it = 1:options.periods
|
|||
else
|
||||
[tmp, check, ~, ~, errorcode] = dynare_solve(@dynamic_static_model_for_simulation, y, ...
|
||||
options.simul.maxit, options.dynatol.f, options.dynatol.x, ...
|
||||
options, dynamicmodel, exogenousvariables, M.params, steadystate, it);
|
||||
options, dynamic_resid, dynamic_g1, x, M.params, steadystate, M.dynamic_g1_sparse_rowval, M.dynamic_g1_sparse_colval, M.dynamic_g1_sparse_colptr);
|
||||
if check
|
||||
info.status = false;
|
||||
if options.debug
|
||||
|
@ -87,17 +84,18 @@ end
|
|||
|
||||
end
|
||||
|
||||
function [r, J] = dynamic_static_model_for_simulation(z, dynamicmodel, x, params, steady_state, it_)
|
||||
function [r, J] = dynamic_static_model_for_simulation(z, dynamic_resid, dynamic_g1, x, params, steady_state, sparse_rowval, sparse_colval, sparse_colptr)
|
||||
|
||||
% NOTE: It is assumed that all variables appear at time t in the model.
|
||||
endo_nbr = length(z);
|
||||
|
||||
y = [ NaN(endo_nbr, 1); z; NaN(endo_nbr, 1)];
|
||||
|
||||
[r, T_order, T] = dynamic_resid(y, x, params, steady_state);
|
||||
|
||||
if nargout>1
|
||||
% Compute residuals and jacobian of the full dynamic model.
|
||||
[r, J] = feval(dynamicmodel, z, x, params, steady_state, it_);
|
||||
J = J(:,1:rows(J)); % Remove derivatives with respect to shocks.
|
||||
else
|
||||
% Compute residuals.
|
||||
r = feval(dynamicmodel, z, x, params, steady_state, it_);
|
||||
Jacobian = dynamic_g1(y, x, params, steady_state, sparse_rowval, ...
|
||||
sparse_colval, sparse_colptr, T_order, T);
|
||||
J = Jacobian(:, endo_nbr+(1:endo_nbr));
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue