### Ensure that all perfect foresight solvers work with periods=1.

`See #1205 and #1176.`
parent c5c13077
 function [residuals,JJacobian] = linear_perfect_foresight_problem(y, dynamicjacobian, Y0, YT, ... exo_simul, params, steady_state, ... maximum_lag, T, ny, i_cols, ... i_cols_J1, i_cols_1, i_cols_T, ... i_cols_j,nnzJ,jendo,jexog) % function [residuals,JJacobian] = perfect_foresight_problem(x, model_dynamic, Y0, YT,exo_simul, % params, steady_state, maximum_lag, periods, ny, i_cols,i_cols_J1, i_cols_1, % i_cols_T, i_cols_j, nnzA) % computes the residuals and th Jacobian matrix % for a perfect foresight problem over T periods. exo_simul, params, steady_state, maximum_lag, T, ny, i_cols, ... i_cols_J1, i_cols_1, i_cols_T, i_cols_j, i_cols_0, i_cols_J0, nnzJ, jendo, jexog) % Computes the residuals and the Jacobian matrix for a linear perfect foresight problem over T periods. % % INPUTS % ... % ... % % OUTPUTS % ... % ... % % ALGORITHM % ... % ... % % SPECIAL REQUIREMENTS % None. % Copyright (C) 2015-2017 Dynare Team % Copyright (C) 2015-2019 Dynare Team % % This file is part of Dynare. % ... ... @@ -44,7 +41,7 @@ residuals = zeros(T*ny,1); z = zeros(columns(dynamicjacobian), 1); if nargout == 2 JJacobian = sparse([],[],[],T*ny,T*ny,T*nnzJ); JJacobian = spalloc(T*ny, T*ny, T*nnzJ); end i_rows = 1:ny; ... ... @@ -55,7 +52,9 @@ for it = maximum_lag+(1:T) z(jexog) = transpose(exo_simul(it,:)); residuals(i_rows) = dynamicjacobian*z; if nargout == 2 if it == maximum_lag+1 if T==1 && it==maximum_lag+1 JJacobian(i_rows, i_cols_J0) = dynamicjacobian(:,i_cols_0); elseif it == maximum_lag+1 JJacobian(i_rows,i_cols_J1) = dynamicjacobian(:,i_cols_1); elseif it == maximum_lag+T JJacobian(i_rows,i_cols_J(i_cols_T)) = dynamicjacobian(:,i_cols_T); ... ...
 ... ... @@ -2,7 +2,7 @@ function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_functi exo_simul, params, steady_state, ... maximum_lag, T, ny, i_cols, ... i_cols_J1, i_cols_1, i_cols_T, ... i_cols_j,nnzJ,eq_index) i_cols_j, i_cols_0,i_cols_J0, nnzJ,eq_index) % function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_function, Y0, YT, ... % exo_simul, params, steady_state, ... % maximum_lag, T, ny, i_cols, ... ... ... @@ -80,10 +80,12 @@ for it = maximum_lag+(1:T) steady_state,it); residuals(i_rows) = res(eq_index); elseif nargout == 2 [res,jacobian] = dynamic_function(YY(i_cols),exo_simul, params, ... steady_state,it); [res,jacobian] = dynamic_function(YY(i_cols),exo_simul, params, steady_state,it); residuals(i_rows) = res(eq_index); if it == maximum_lag+1 if T==1 && it==maximum_lag+1 [rows, cols, vals] = find(jacobian(:,i_cols_0)); iJacobian{1} = [rows, i_cols_J0(cols), vals]; elseif it == maximum_lag+1 [rows,cols,vals] = find(jacobian(eq_index,i_cols_1)); iJacobian{1} = [offset+rows, i_cols_J1(cols), vals]; elseif it == maximum_lag+T ... ... @@ -103,6 +105,5 @@ end if nargout == 2 iJacobian = cat(1,iJacobian{:}); JJacobian = sparse(iJacobian(:,1),iJacobian(:,2),iJacobian(:,3),T* ... ny,T*ny); JJacobian = sparse(iJacobian(:,1),iJacobian(:,2),iJacobian(:,3),T*ny,T*ny); end \ No newline at end of file