1function [endogenousvariables, info] = sim1_purely_backward(endogenousvariables, exogenousvariables, steadystate, M, options)
2
3% Performs deterministic simulation of a purely backward model
4
5% Copyright (C) 2012-2017 Dynare Team
6%
7% This file is part of Dynare.
8%
9% Dynare is free software: you can redistribute it and/or modify
10% it under the terms of the GNU General Public License as published by
11% the Free Software Foundation, either version 3 of the License, or
12% (at your option) any later version.
13%
14% Dynare is distributed in the hope that it will be useful,
15% but WITHOUT ANY WARRANTY; without even the implied warranty of
16% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17% GNU General Public License for more details.
18%
19% You should have received a copy of the GNU General Public License
20% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
21
22if size(M.lead_lag_incidence,1) > 1
23    ny0 = nnz(M.lead_lag_incidence(2,:));    % Number of variables at current period
24    nyb = nnz(M.lead_lag_incidence(1,:));    % Number of variables at previous period
25    iyb = find(M.lead_lag_incidence(1,:)>0); % Indices of variables at previous period
26else
27    ny0 = nnz(M.lead_lag_incidence(1,:));    % Number of variables at current period
28    nyb = 0;
29    iyb = [];
30end
31
32
33if ny0 ~= M.endo_nbr
34    error('All endogenous variables must appear at the current period!')
35end
36
37dynamicmodel = str2func([M.fname,'.dynamic']);
38
39info.status = 1;
40
41for it = M.maximum_lag + (1:options.periods)
42    yb = endogenousvariables(:,it-1);        % Values at previous period, also used as guess value for current period
43    yb1 = yb(iyb);
44    [tmp, check] = solve1(dynamicmodel, [yb1; yb], 1:M.endo_nbr, nyb+1:nyb+M.endo_nbr, ...
45                          1, options.gstep, options.dynatol.f, options.dynatol.x, ...
46                          options.simul.maxit, options.debug, exogenousvariables, ...
47                          M.params, steadystate, it);
48    if check
49        info.status = 0;
50    end
51    endogenousvariables(:,it) = tmp(nyb+1:nyb+M.endo_nbr);
52end