From 9a4de2c819a248c1d01ad8325b5c1da2f9de9007 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Tue, 5 Feb 2019 09:14:20 +0100
Subject: [PATCH] discretionary_policy_1.m: check for NaN before checking for
 non-zero derivatives

Prevents false error message

(manually cherry picked from commit 8cb99bfe9dad05acf6d82447c7e974c1e1148707)
---
 matlab/discretionary_policy_1.m | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/matlab/discretionary_policy_1.m b/matlab/discretionary_policy_1.m
index 8f8bf6b8a2..bcb255dbae 100644
--- a/matlab/discretionary_policy_1.m
+++ b/matlab/discretionary_policy_1.m
@@ -67,6 +67,9 @@ if options_.steadystate_flag
                                                       options_,0);
 end
 [U,Uy,W] = feval([M_.fname,'_objective_static'],zeros(endo_nbr,1),[], M_.params);
+if any(any(isnan(Uy)))
+    error(['discretionary_policy: the derivatives of the objective function contain NaN'])
+end
 if any(any(Uy~=0))
     error(['discretionary_policy: the objective function must have zero ' ...
            'first order derivatives'])
-- 
GitLab