Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Marco Ratto
dynare
Commits
74dc4f81
Commit
74dc4f81
authored
May 17, 2022
by
Johannes Pfeifer
Browse files
perfect_foresight_solver.m: loop over dynamic file when mex cannot be used
Closes
Dynare/dynare#1850
parent
05ab494d
Changes
1
Hide whitespace changes
Inline
Side-by-side
matlab/perfect-foresight-models/perfect_foresight_solver.m
View file @
74dc4f81
...
...
@@ -192,9 +192,9 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy
warning
(
warning_old_state
);
end
%If simulated paths are complex, take real part and recompute the residuals to check whether this is actually a solution
if
~
isreal
(
oo_
.
endo_simul
(:))
% cannot happen with bytecode or the perfect_foresight_problem DLL
ny
=
size
(
oo_
.
endo_simul
,
1
)
ny
=
size
(
oo_
.
endo_simul
,
1
)
;
if
M_
.
maximum_lag
>
0
y0
=
real
(
oo_
.
endo_simul
(:,
M_
.
maximum_lag
));
else
...
...
@@ -205,9 +205,20 @@ if ~isreal(oo_.endo_simul(:)) % cannot happen with bytecode or the perfect_fores
else
yT
=
NaN
(
ny
,
1
);
end
yy
=
real
(
oo_
.
endo_simul
(:,
M_
.
maximum_lag
+
(
1
:
periods
)));
residuals
=
perfect_foresight_problem
(
yy
(:),
y0
,
yT
,
oo_
.
exo_simul
,
M_
.
params
,
oo_
.
steady_state
,
periods
,
M_
,
options_
);
if
M_
.
maximum_lag
~=
0
&&
M_
.
maximum_lead
~=
0
yy
=
real
(
oo_
.
endo_simul
(:,
M_
.
maximum_lag
+
(
1
:
periods
)));
residuals
=
perfect_foresight_problem
(
yy
(:),
y0
,
yT
,
oo_
.
exo_simul
,
M_
.
params
,
oo_
.
steady_state
,
periods
,
M_
,
options_
);
else
%The perfect_foresight_problem MEX only works on models with lags and leads
i_cols
=
find
(
M_
.
lead_lag_incidence
'
);
residuals
=
NaN
(
ny
,
periods
);
yy
=
real
(
oo_
.
endo_simul
);
for
it
=
(
M_
.
maximum_lag
+
1
):(
M_
.
maximum_lag
+
periods
)
residuals
(:,
it
)
=
feval
([
M_
.
fname
'.dynamic'
],
yy
(
i_cols
),
oo_
.
exo_simul
,
M_
.
params
,
oo_
.
steady_state
,
it
);
i_cols
=
i_cols
+
ny
;
end
residuals
=
residuals
(:);
end
if
max
(
abs
(
residuals
))
<
options_
.
dynatol
.
f
oo_
.
deterministic_simulation
.
status
=
true
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment