From 9dfc0d5c08f23f21a87e70b58fc826c5bc06c594 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Sat, 4 Feb 2012 18:52:03 +0100
Subject: [PATCH] Added calls to matlab implementation of the perfect foresight
 solver in homotopic routine (extended path approach).

---
 matlab/ep/extended_path.m   |  4 ++--
 matlab/ep/homotopic_steps.m | 23 ++++++++++++++++++++---
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/matlab/ep/extended_path.m b/matlab/ep/extended_path.m
index 1e07356429..23c6a36d86 100644
--- a/matlab/ep/extended_path.m
+++ b/matlab/ep/extended_path.m
@@ -349,9 +349,9 @@ while (t<sample_size)
             end
         end% while
         if ~info.convergence% If exited from the while loop without achieving convergence, use an homotopic approach
-            [INFO,tmp] = homotopic_steps(.5,.01);
+            [INFO,tmp] = homotopic_steps(.5,.01,pfm);
             if (~isstruct(INFO) && isnan(INFO)) || ~INFO.convergence
-                [INFO,tmp] = homotopic_steps(0,.01);
+                [INFO,tmp] = homotopic_steps(0,.01,pfm);
                 if ~INFO.convergence
                     disp('Homotopy:: No convergence of the perfect foresight model solver!')
                     error('I am not able to simulate this model!');
diff --git a/matlab/ep/homotopic_steps.m b/matlab/ep/homotopic_steps.m
index 3801e003e4..609966c4b9 100644
--- a/matlab/ep/homotopic_steps.m
+++ b/matlab/ep/homotopic_steps.m
@@ -1,6 +1,9 @@
-function [info,tmp] = homotopic_steps(initial_weight,step_length)
+function [info,tmp] = homotopic_steps(initial_weight,step_length,pfm)
 global oo_ options_ M_
 
+%Set bytecode flag
+bytecode_flag = options_.ep.use_bytecode;
+
 % Set increase and decrease factors.
 increase_factor = 5.0;
 decrease_factor = 0.2;
@@ -53,7 +56,14 @@ for d=1:stochastic_extended_path_depth
         if d>1
             oo_.exo_simul(1:idx(d-1),:) = exxo_simul(1:idx(d-1),:);
         end
-        [flag,tmp] = bytecode('dynamic');
+        if bytecode_flag
+            [flag,tmp] = bytecode('dynamic');
+        else
+            flag = 1;
+        end
+        if flag
+            [flag,tmp] = solve_perfect_foresight_model(oo_.endo_simul,oo_.exo_simul,pfm);
+        end
         info.convergence = ~flag;% Equal to one if the perfect foresight solver converged for the current value of weight.
         if verbose
             if info.convergence
@@ -117,7 +127,14 @@ for d=1:stochastic_extended_path_depth
     end
     if weight<1
         oo_.exo_simul = exxo_simul;
-        [flag,tmp] = bytecode('dynamic');
+        if bytecode_flag
+            [flag,tmp] = bytecode('dynamic');
+        else
+            flag = 1;
+        end
+        if flag
+            [flag,tmp] = solve_perfect_foresight_model(oo_.endo_simul,oo_.exo_simul,pfm);
+        end
         info.convergence = ~flag;
         if info.convergence
             oo_.endo_simul = tmp;
-- 
GitLab