2017-05-16 12:02:57 +02:00
|
|
|
function [residuals,JJacobian] = linear_perfect_foresight_problem(y, dynamicjacobian, Y0, YT, ...
|
2019-04-26 15:36:33 +02:00
|
|
|
exo_simul, params, steady_state, maximum_lag, T, ny, i_cols, ...
|
2019-05-07 18:31:47 +02:00
|
|
|
i_cols_J1, i_cols_1, i_cols_T, i_cols_j, i_cols_0, i_cols_J0, jendo, jexog)
|
2019-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
% Computes the residuals and the Jacobian matrix for a linear perfect foresight problem over T periods.
|
2015-07-07 15:08:38 +02:00
|
|
|
%
|
|
|
|
% INPUTS
|
2019-04-26 15:36:33 +02:00
|
|
|
% ...
|
|
|
|
%
|
2015-07-07 15:08:38 +02:00
|
|
|
% OUTPUTS
|
2019-04-26 15:36:33 +02:00
|
|
|
% ...
|
|
|
|
%
|
2015-07-07 15:08:38 +02:00
|
|
|
% ALGORITHM
|
2019-04-26 15:36:33 +02:00
|
|
|
% ...
|
2015-07-07 15:08:38 +02:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% None.
|
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2015-2020 Dynare Team
|
2015-07-07 15:08:38 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2015-07-07 15:08:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
YY = [Y0; y; YT];
|
|
|
|
|
|
|
|
residuals = zeros(T*ny,1);
|
|
|
|
|
|
|
|
z = zeros(columns(dynamicjacobian), 1);
|
|
|
|
|
|
|
|
if nargout == 2
|
2019-04-26 16:20:45 +02:00
|
|
|
iJacobian = cell(T,1);
|
2015-07-07 15:08:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
i_rows = 1:ny;
|
|
|
|
i_cols_J = i_cols;
|
2019-04-26 16:20:45 +02:00
|
|
|
offset = 0;
|
2015-07-07 15:08:38 +02:00
|
|
|
|
|
|
|
for it = maximum_lag+(1:T)
|
|
|
|
z(jendo) = YY(i_cols);
|
|
|
|
z(jexog) = transpose(exo_simul(it,:));
|
|
|
|
residuals(i_rows) = dynamicjacobian*z;
|
|
|
|
if nargout == 2
|
2019-04-26 15:36:33 +02:00
|
|
|
if T==1 && it==maximum_lag+1
|
2019-04-26 16:20:45 +02:00
|
|
|
[rows, cols, vals] = find(dynamicjacobian(:,i_cols_0));
|
2020-10-20 17:34:11 +02:00
|
|
|
if size(dynamicjacobian, 1) == 1 % find() will return row vectors in this case
|
|
|
|
rows = rows';
|
|
|
|
cols = cols';
|
|
|
|
vals = vals';
|
|
|
|
end
|
2019-04-26 16:20:45 +02:00
|
|
|
iJacobian{1} = [rows, i_cols_J0(cols), vals];
|
2019-04-26 15:36:33 +02:00
|
|
|
elseif it == maximum_lag+1
|
2019-04-26 16:20:45 +02:00
|
|
|
[rows,cols,vals] = find(dynamicjacobian(:,i_cols_1));
|
2020-10-20 17:34:11 +02:00
|
|
|
if size(dynamicjacobian, 1) == 1 % find() will return row vectors in this case
|
|
|
|
rows = rows';
|
|
|
|
cols = cols';
|
|
|
|
vals = vals';
|
|
|
|
end
|
2019-04-26 16:20:45 +02:00
|
|
|
iJacobian{1} = [offset+rows, i_cols_J1(cols), vals];
|
2018-06-07 16:14:02 +02:00
|
|
|
elseif it == maximum_lag+T
|
2019-04-26 16:20:45 +02:00
|
|
|
[rows,cols,vals] = find(dynamicjacobian(:,i_cols_T));
|
2020-10-20 17:34:11 +02:00
|
|
|
if size(dynamicjacobian, 1) == 1 % find() will return row vectors in this case
|
|
|
|
rows = rows';
|
|
|
|
cols = cols';
|
|
|
|
vals = vals';
|
|
|
|
end
|
2019-04-26 16:20:45 +02:00
|
|
|
iJacobian{T} = [offset+rows, i_cols_J(i_cols_T(cols)), vals];
|
2015-07-07 15:08:38 +02:00
|
|
|
else
|
2019-04-26 16:20:45 +02:00
|
|
|
[rows,cols,vals] = find(dynamicjacobian(:,i_cols_j));
|
2020-10-20 17:34:11 +02:00
|
|
|
if size(dynamicjacobian, 1) == 1 % find() will return row vectors in this case
|
|
|
|
rows = rows';
|
|
|
|
cols = cols';
|
|
|
|
vals = vals';
|
|
|
|
end
|
2019-04-26 16:20:45 +02:00
|
|
|
iJacobian{it-maximum_lag} = [offset+rows, i_cols_J(cols), vals];
|
2015-07-07 15:08:38 +02:00
|
|
|
i_cols_J = i_cols_J + ny;
|
|
|
|
end
|
2019-04-26 16:20:45 +02:00
|
|
|
offset = offset + ny;
|
2015-07-07 15:08:38 +02:00
|
|
|
end
|
|
|
|
i_rows = i_rows + ny;
|
|
|
|
i_cols = i_cols + ny;
|
2019-04-26 16:20:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if nargout == 2
|
|
|
|
iJacobian = cat(1,iJacobian{:});
|
|
|
|
JJacobian = sparse(iJacobian(:,1), iJacobian(:,2), iJacobian(:,3), T*ny, T*ny);
|
2019-05-07 18:31:47 +02:00
|
|
|
end
|