From 1db8b0d27773601b628083a47526d72d84cda59b Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Fri, 10 Jul 2009 13:14:17 +0000
Subject: [PATCH] Homotopy: * fixed bug with Octave in modes 1 and 3 * enhanced
 tests

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2832 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 matlab/homotopy1.m                |  4 ++--
 matlab/homotopy2.m                |  2 +-
 matlab/homotopy3.m                |  4 ++--
 tests/Makefile.in                 |  4 +++-
 tests/homotopy/common.mod         | 22 ++++++++++++++++++++++
 tests/homotopy/homotopy1_test.mod |  2 ++
 tests/homotopy/homotopy2_test.mod |  2 ++
 tests/homotopy/homotopy3_test.mod |  4 ++++
 tests/homotopy/ramst_final.mod    | 13 -------------
 tests/homotopy/ramst_homotopy.mod | 20 --------------------
 tests/homotopy/ramst_initial.mod  | 13 -------------
 11 files changed, 38 insertions(+), 52 deletions(-)
 create mode 100644 tests/homotopy/homotopy1_test.mod
 create mode 100644 tests/homotopy/homotopy2_test.mod
 create mode 100644 tests/homotopy/homotopy3_test.mod
 delete mode 100644 tests/homotopy/ramst_final.mod
 delete mode 100644 tests/homotopy/ramst_homotopy.mod
 delete mode 100644 tests/homotopy/ramst_initial.mod

diff --git a/matlab/homotopy1.m b/matlab/homotopy1.m
index 1d76eda5d3..db11e1de41 100644
--- a/matlab/homotopy1.m
+++ b/matlab/homotopy1.m
@@ -23,7 +23,7 @@ function homotopy1(values, step_nbr)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright (C) 2008 Dynare Team
+% Copyright (C) 2008-2009 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -48,7 +48,7 @@ function homotopy1(values, step_nbr)
   ix = find(values(:,1) == 1); % Exogenous
   ixd = find(values(:,1) == 2); % Exogenous deterministic
 
-  if length([ip, ix, ixd]) ~= nv
+  if length([ip; ix; ixd]) ~= nv
     error('HOMOTOPY mode 1: incorrect variable types specified')
   end
 
diff --git a/matlab/homotopy2.m b/matlab/homotopy2.m
index 2425e12c5a..eb53778d2a 100644
--- a/matlab/homotopy2.m
+++ b/matlab/homotopy2.m
@@ -25,7 +25,7 @@ function homotopy2(values, step_nbr)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright (C) 2008 Dynare Team
+% Copyright (C) 2008-2009 Dynare Team
 %
 % This file is part of Dynare.
 %
diff --git a/matlab/homotopy3.m b/matlab/homotopy3.m
index c3fc9ddbe8..15148fd227 100644
--- a/matlab/homotopy3.m
+++ b/matlab/homotopy3.m
@@ -25,7 +25,7 @@ function homotopy3(values, step_nbr)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright (C) 2008 Dynare Team
+% Copyright (C) 2008-2009 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -52,7 +52,7 @@ function homotopy3(values, step_nbr)
   ix = find(values(:,1) == 1); % Exogenous
   ixd = find(values(:,1) == 2); % Exogenous deterministic
 
-  if length([ip, ix, ixd]) ~= nv
+  if length([ip; ix; ixd]) ~= nv
     error('HOMOTOPY mode 3: incorrect variable types specified')
   end
 
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 1e18007528..ac940d3813 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -16,7 +16,9 @@ OCTAVE_MODS = \
 	arima/mod2.mod \
 	arima/mod2c.mod \
 	fs2000/fs2000.mod \
-	homotopy/ramst_homotopy.mod \
+	homotopy/homotopy1_test.mod \
+	homotopy/homotopy2_test.mod \
+	homotopy/homotopy3_test.mod \
 	bvar_a_la_sims/bvar_standalone.mod \
 	bvar_a_la_sims/bvar_and_dsge.mod
 
diff --git a/tests/homotopy/common.mod b/tests/homotopy/common.mod
index c643542c57..347dd464ab 100644
--- a/tests/homotopy/common.mod
+++ b/tests/homotopy/common.mod
@@ -6,8 +6,30 @@ alph=0.5;
 gam=0.5;
 delt=0.02;
 aa=0.5;
+bet=0.05;
 
 model;
 c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
 c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
 end;
+
+initval;
+x = 1;
+k = ((delt+bet)/(aa*x*alph))^(1/(alph-1));
+c = aa*x*k^alph-delt*k;
+end;
+
+homotopy_setup;
+bet, 0.05, 0.1;
+x, 2;
+end;
+
+steady(homotopy_mode = @{homotopy_mode}, homotopy_steps = 50);
+
+if abs(oo_.steady_state(1)/(aa*oo_.exo_steady_state(1)*oo_.steady_state(2)^alph-delt*oo_.steady_state(2)) - 1) > 1e-4
+   error('Error in homotopy for c')
+end
+
+if abs(oo_.steady_state(2)/((delt+get_param_by_name('bet'))/(aa*oo_.exo_steady_state(1)*alph))^(1/(alph-1)) - 1) > 1e-4
+   error('Error in homotopy for k')
+end
diff --git a/tests/homotopy/homotopy1_test.mod b/tests/homotopy/homotopy1_test.mod
new file mode 100644
index 0000000000..fe24c5194d
--- /dev/null
+++ b/tests/homotopy/homotopy1_test.mod
@@ -0,0 +1,2 @@
+@#define homotopy_mode = 1
+@#include "common.mod"
diff --git a/tests/homotopy/homotopy2_test.mod b/tests/homotopy/homotopy2_test.mod
new file mode 100644
index 0000000000..cf0b8a80d8
--- /dev/null
+++ b/tests/homotopy/homotopy2_test.mod
@@ -0,0 +1,2 @@
+@#define homotopy_mode = 2
+@#include "common.mod"
diff --git a/tests/homotopy/homotopy3_test.mod b/tests/homotopy/homotopy3_test.mod
new file mode 100644
index 0000000000..74b5fc6115
--- /dev/null
+++ b/tests/homotopy/homotopy3_test.mod
@@ -0,0 +1,4 @@
+// This test is not very thorough since homotopy will succeed at first step...
+
+@#define homotopy_mode = 3
+@#include "common.mod"
diff --git a/tests/homotopy/ramst_final.mod b/tests/homotopy/ramst_final.mod
deleted file mode 100644
index 6e49900aaf..0000000000
--- a/tests/homotopy/ramst_final.mod
+++ /dev/null
@@ -1,13 +0,0 @@
-// Computes the steady state which should be arrived at in ramst_homotopy.mod
-
-@#include "common.mod"
-
-bet = 0.1;
-
-initval;
-x = 2;
-k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
-c = aa*k^alph-delt*k;
-end;
-
-steady;
diff --git a/tests/homotopy/ramst_homotopy.mod b/tests/homotopy/ramst_homotopy.mod
deleted file mode 100644
index 368311d3ed..0000000000
--- a/tests/homotopy/ramst_homotopy.mod
+++ /dev/null
@@ -1,20 +0,0 @@
-// Contains the test for homotopy.
-// The values in initval block are obtained from ramst_initial.mod 
-// Result of the computation should be the same than in ramst_final.mod
-
-@#include "common.mod"
-
-initval;
-k = 12.75;
-c = 1.5;
-x = 1;
-end;
-
-homotopy_setup;
-bet, 0.05, 0.1;
-x, 2;
-end;
-
-steady(homotopy_mode = 2, homotopy_steps = 50);
-//steady(homotopy_mode = 2, homotopy_steps = 50);
-//steady(homotopy_mode = 3, homotopy_steps = 50);
diff --git a/tests/homotopy/ramst_initial.mod b/tests/homotopy/ramst_initial.mod
deleted file mode 100644
index 0d74511ddc..0000000000
--- a/tests/homotopy/ramst_initial.mod
+++ /dev/null
@@ -1,13 +0,0 @@
-// Computes the steady state used in initval block of ramst_homotopy.mod
-
-@#include "common.mod"
-
-bet=0.05;
-
-initval;
-x = 1;
-k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
-c = aa*k^alph-delt*k;
-end;
-
-steady;
-- 
GitLab