From d46a3b18973d1f2844ef87624016902e8877034b Mon Sep 17 00:00:00 2001
From: michel <michel@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Fri, 20 Mar 2009 10:14:02 +0000
Subject: [PATCH] 4.0: merged r2275 changeset from trunk (update OSR for unit
 roots)

git-svn-id: https://www.dynare.org/svn/dynare/branches/4.0@2482 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 matlab/osr1.m | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/matlab/osr1.m b/matlab/osr1.m
index 29d8b1f5c2..42000c0e1d 100644
--- a/matlab/osr1.m
+++ b/matlab/osr1.m
@@ -40,18 +40,39 @@ function osr1(i_params,i_var,weights)
 
   exe =zeros(M_.exo_nbr,1);
   
-  oo_.dr = set_state_space(oo_.dr,M_);
+  dr = set_state_space(oo_.dr,M_);
   
   % check if ys is steady state
-  fh = str2func([M_.fname '_static']);
-  if max(abs(feval(fh, oo_.steady_state, exe, M_.params))) > options_.dynatol
-    [oo_.dr.ys, check] = dynare_solve([M_.fname '_static'], oo_.steady_state, 1, exe, M_.params);
-    if check
-      error('OLR: convergence problem in DYNARE_SOLVE')
-    end
+  if exist([M_.fname '_steadystate'])
+      [dr.ys,check1] = feval([M_.fname '_steadystate'],oo_.steady_state,...
+                             [oo_.exo_steady_state; oo_.exo_det_steady_state]);
   else
-    oo_.dr.ys = oo_.steady_state;
+      % testing if ys isn't a steady state or if we aren't computing Ramsey policy
+      fh = str2func([M_.fname '_static']);
+      if max(abs(feval(fh,oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state], M_.params))) ...
+              > options_.dynatol & options_.ramsey_policy == 0
+          if options_.linear == 0
+              % nonlinear models
+              [dr.ys,check1] = dynare_solve(fh,dr.ys,options_.jacobian_flag,...
+                                            [oo_.exo_steady_state; ...
+		    oo_.exo_det_steady_state], M_.params);
+          else
+              % linear models
+              [fvec,jacob] = feval(fh,oo_.steady_state,[oo_.exo_steady_state;...
+		    oo_.exo_det_steady_state], M_.params);
+              dr.ys = oo_.steady_state-jacob\fvec;
+          end
+      end
   end
+  oo_.dr = dr;
+% $$$   if max(abs(feval(fh, oo_.steady_state, exe, M_.params))) > options_.dynatol
+% $$$     [oo_.dr.ys, check] = dynare_solve([M_.fname '_static'], oo_.steady_state, 1, exe, M_.params);
+% $$$     if check
+% $$$       error('OLR: convergence problem in DYNARE_SOLVE')
+% $$$     end
+% $$$   else
+% $$$     oo_.dr.ys = oo_.steady_state;
+% $$$   end
 
   
   np = size(i_params,1);
-- 
GitLab