From 38ba90e0046f75796a02fab694e7ff11d8649b75 Mon Sep 17 00:00:00 2001 From: ratto Date: Mon, 20 Apr 2009 12:09:44 +0000 Subject: [PATCH] Traps for bad x values in optimizer. git-svn-id: https://www.dynare.org/svn/dynare/trunk@2611 ac1d8469-bf42-47a9-8791-bf33cf982152 --- matlab/mr_gstep.m | 4 ++++ matlab/mr_hessian.m | 16 ++++++++++++++-- matlab/newrat.m | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/matlab/mr_gstep.m b/matlab/mr_gstep.m index 7c36e1017..6a0e7f927 100644 --- a/matlab/mr_gstep.m +++ b/matlab/mr_gstep.m @@ -89,7 +89,11 @@ while i(2*htol), h1(i)= htol/abs(dx(it))*h1(i); xh1(i)=x(i)+h1(i); - [fx, ffx]=feval(func,xh1,varargin{:}); + try + [fx, ffx]=feval(func,xh1,varargin{:}); + catch + fx=1.e8; + end while (fx-f0)==0, h1(i)= h1(i)*2; xh1(i)=x(i)+h1(i); diff --git a/matlab/newrat.m b/matlab/newrat.m index 87d353bfb..7e5992243 100644 --- a/matlab/newrat.m +++ b/matlab/newrat.m @@ -197,7 +197,11 @@ while norm(gg)>gtol & check==0 & jit1.e-12, + try save m1 x fval0 nig -append + catch + save m1 x fval0 nig + end [dum, gg, htol0, igg, hhg]=mr_hessian(func_hh,xparam1,flagit,htol,varargin{:}); if htol0>htol, %ftol, %ftol=htol0;