Bug fix. Revert to previous Jacobian matrix if updated one is ill-behaved.

trustregion
Stéphane Adjemian (Ryûk) 2022-03-25 19:28:32 +01:00
parent 79cad99446
commit 4cccdd9074
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
1 changed files with 4 additions and 1 deletions

View File

@ -109,7 +109,7 @@ catch
end
if any(isnan(fval)) || any(isinf(fval)) || any(~isreal(fval)) || any(isnan(fjac(:))) || any(isinf(fjac(:))) || any(~isreal(fjac(:)))
% System of equations is ill-behaved at the initial guess.
% System of equations is ill-behaved at the initial guess.
return
end
@ -251,6 +251,7 @@ while iter<=maxiter && ~info
continue
end
% Compute the jacobian for the next iteration.
fjac0 = fjac;
if jacobianflag
try
[~, fjac] = objfun(x, varargin{:});
@ -258,6 +259,7 @@ while iter<=maxiter && ~info
catch
% If evaluation of the Jacobian matrix returns an error, then restart but with a smaller radius of the trust region.
x = x0;
fjac = fjac0;
delta = delta*radiusfactor;
continue
end
@ -273,6 +275,7 @@ while iter<=maxiter && ~info
if any(isnan(fjac(:))) || any(isinf(fjac(:))) || any(~isreal(fjac(:)))
% If evaluation of the Jacobian matrix returns NaNs, an infinite numbers or a complex numbers, then restart but with a smaller radius of the trust region.
x = x0;
fjac = fjac0;
delta = delta*radiusfactor;
end
end