From 547969df452d1d1b65d447fce1dc88f8bfe8756e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 15 Jan 2021 17:17:48 +0100 Subject: [PATCH] Trust region: compatibility fix for Octave and MATLAB < R2017b When merging the enterprise code, the dogleg subfunction was modified to incorporate a call to decomposition(), which does not exist under Octave and MATLAB < R2017b. For those cases, we reinstate the old code (which uses a plain matrix right divide). --- matlab/trust_region.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/matlab/trust_region.m b/matlab/trust_region.m index 5069a37df..a8a254625 100644 --- a/matlab/trust_region.m +++ b/matlab/trust_region.m @@ -25,7 +25,7 @@ function [x,check,info] = trust_region(fcn,x0,j1,j2,jacobian_flag,gstep,tolf,tol % none % Copyright (C) 2008-2012 VZLU Prague, a.s. -% Copyright (C) 2014-2020 Dynare Team +% Copyright (C) 2014-2021 Dynare Team % % This file is part of Dynare. % @@ -188,7 +188,12 @@ end function x = dogleg (r, b, d, delta) % Get Gauss-Newton direction. -x = decomposition(r, 'CheckCondition', false) \ b; +if isoctave || matlab_ver_less_than('9.3') + % The decomposition() function does not exist in Octave and MATLAB < R2017b + x = r \ b; +else + x = decomposition(r, 'CheckCondition', false) \ b; +end xn = norm (d .* x); if (xn > delta) % GN is too big, get scaled gradient.