From fad86785da4c53a5b5dfd69f19cce769e23d6135 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Fri, 28 May 2021 16:59:28 +0200
Subject: [PATCH] evaluate_planner_objective.m: do not evaluate non-existing
 terms for linear models

Closes https://git.dynare.org/Dynare/dynare/-/issues/1781
---
 matlab/evaluate_planner_objective.m | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/matlab/evaluate_planner_objective.m b/matlab/evaluate_planner_objective.m
index 3f09ca3fa3..e61aab2633 100644
--- a/matlab/evaluate_planner_objective.m
+++ b/matlab/evaluate_planner_objective.m
@@ -98,11 +98,11 @@ if options_.ramsey_policy
         planner_objective_value(2) = W;
     else
     ys = oo_.dr.ys;
-        if options_.order == 1
+        if options_.order == 1 || M_.hessian_eq_zero
             [U] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
             planner_objective_value(1) = U/(1-beta);
             planner_objective_value(2) = U/(1-beta);  
-        elseif options_.order == 2
+        elseif options_.order == 2 && ~M_.hessian_eq_zero
             [U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
 
             Gy = dr.ghx(nstatic+(1:nspred),:);
-- 
GitLab