Bug fix. Revert to previous Jacobian matrix if updated one is ill-behaved.
parent
79cad99446
commit
4cccdd9074
|
@ -109,7 +109,7 @@ catch
|
||||||
end
|
end
|
||||||
|
|
||||||
if any(isnan(fval)) || any(isinf(fval)) || any(~isreal(fval)) || any(isnan(fjac(:))) || any(isinf(fjac(:))) || any(~isreal(fjac(:)))
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -251,6 +251,7 @@ while iter<=maxiter && ~info
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
% Compute the jacobian for the next iteration.
|
% Compute the jacobian for the next iteration.
|
||||||
|
fjac0 = fjac;
|
||||||
if jacobianflag
|
if jacobianflag
|
||||||
try
|
try
|
||||||
[~, fjac] = objfun(x, varargin{:});
|
[~, fjac] = objfun(x, varargin{:});
|
||||||
|
@ -258,6 +259,7 @@ while iter<=maxiter && ~info
|
||||||
catch
|
catch
|
||||||
% If evaluation of the Jacobian matrix returns an error, then restart but with a smaller radius of the trust region.
|
% If evaluation of the Jacobian matrix returns an error, then restart but with a smaller radius of the trust region.
|
||||||
x = x0;
|
x = x0;
|
||||||
|
fjac = fjac0;
|
||||||
delta = delta*radiusfactor;
|
delta = delta*radiusfactor;
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
@ -273,6 +275,7 @@ while iter<=maxiter && ~info
|
||||||
if any(isnan(fjac(:))) || any(isinf(fjac(:))) || any(~isreal(fjac(:)))
|
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.
|
% 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;
|
x = x0;
|
||||||
|
fjac = fjac0;
|
||||||
delta = delta*radiusfactor;
|
delta = delta*radiusfactor;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue