# Deterministic simulation sim1.m

Dear all,

I am trying to understand the simul command in dynare. In sim1.m there is the following code which I do not understand at all:

model_dynamic = str2func([M_.fname,'dynamic’]);
[d1,jacobian] = model_dynamic(z,oo
.exo_simul, params, …

The Y is the stacked vector of all variables (to be determined) at all times of the simulation. At that point it is Y=[Y0,Y1,Y1,…Y1]’, thus the initial points and then the end points times the time of simulation.
The lead_lag_incidence determines the characteristc of each variable (backward looking, forward looking or present).
So far correct?
I do not understand what model_dynamic is (except that it is a function…but what does it do?).
I also do not understand the z variable since it stores values of initial steady states and future steady states.
Last but not least, I do not get the model_dynamic() and what it does. I tried
[d1,jacobian111] = model_dynamic(z,oo_.exo_simul, params, …
AAA=model_dynamic(z,oo_.exo_simul, params, …
[d2,jacobian1] = AAA

The first command works, for the second and third together I get “Too many output arguments.”

Any help is very much appreciated!

Best

model_dynamic is a link to the _dynamic-function created by Dynare. You can find that function in the folder where your mod-file is located after running Dynare. If your model is cally mymodel.mod the file will be mymodel_dynamic.m. This file computes the things as indicated in the header of that file:

[quote]function [residual, g1, g2, g3] = mymodel_dynamic(y, x, params, steady_state, it_)
%
% Status : Computes dynamic model for Dynare
%
% Inputs :
% y #dynamic variables by 1] double vector of endogenous variables in the order stored
% in M_.lead_lag_incidence; see the Manual
% x [M_.exo_nbr by nperiods] double matrix of exogenous variables (in declaration order)
% for all simulation periods
% params [M_.param_nbr by 1] double vector of parameter values in declaration order
% it_ scalar double time period for exogenous variables for which to evaluate the model
%
% Outputs:
% residual [M_.endo_nbr by 1] double vector of residuals of the dynamic model equations in order of
% declaration of the equations
% g1 [M_.endo_nbr by #dynamic variables] double Jacobian matrix of the dynamic model equations;
% columns: equations in order of declaration
% rows: variables in order stored in M_.lead_lag_incidence
% g2 [M_.endo_nbr by (#dynamic variables)^2] double Hessian matrix of the dynamic model equations;
% columns: equations in order of declaration
% rows: variables in order stored in M_.lead_lag_incidence
% g3 [M_.endo_nbr by (#dynamic variables)^3] double Third order derivative matrix of the dynamic model equations;
% columns: equations in order of declaration
% rows: variables in order stored in M_.lead_lag_incidence
%
%
% Warning : this file is generated automatically by Dynare
% from model file (.mod)

%
% Model equations
%
[/quote]

That is, given the value for the variables in z, it computes the residuals as well as the derivatives of the model.

One more question: Is there a documentation of how perfect foresight is implemented in Dynare? I am only aware of Juillard 1996, but I read from Sebastian Villemots slides of the summer school in 2012 that it is computed differently nowadays. However, I haven’t found any references.