# HG changeset patch # User Rik # Date 1329597826 28800 # Node ID 59aab666f2bf5030b1a0ee58f3ecb265c0592d6c # Parent 310039bc3dd3e1ef8bb38c71f00bb645f7fec540 Extend "FunValCheck" option to optimization routines to detect Inf values. * fminunc.m, fsolve.m: Extend "FunValCheck" option to optimization routines to detect Inf values. diff -r 310039bc3dd3 -r 59aab666f2bf scripts/optimization/fminunc.m --- a/scripts/optimization/fminunc.m Sat Feb 18 11:59:21 2012 -0800 +++ b/scripts/optimization/fminunc.m Sat Feb 18 12:43:46 2012 -0800 @@ -354,9 +354,12 @@ error ("fminunc:notreal", "fminunc: non-real value encountered"); elseif (any (isnan (fx(:)))) error ("fminunc:isnan", "fminunc: NaN value encountered"); + elseif (any (isinf (fx(:)))) + error ("fminunc:isinf", "fminunc: Inf value encountered"); endif endfunction + %!function f = __rosenb (x) %! n = length (x); %! f = sumsq (1 - x(1:n-1)) + 100 * sumsq (x(2:n) - x(1:n-1).^2); @@ -373,6 +376,12 @@ %! assert (info > 0); %! assert (x, ones (1, 4), tol); %! assert (fval, 0, tol); +%% Test FunValCheck works correctly +%!assert (fminunc (@(x) x^2, 1, optimset ("FunValCheck", "on")), 0, eps) +%!error fminunc (@(x) x + i, 1, optimset ("FunValCheck", "on")) +%!error fminunc (@(x) x + NaN, 1, optimset ("FunValCheck", "on")) +%!error fminunc (@(x) x + Inf, 1, optimset ("FunValCheck", "on")) + ## Solve the double dogleg trust-region minimization problem: ## Minimize 1/2*norm(r*x)^2 subject to the constraint norm(d.*x) <= delta, diff -r 310039bc3dd3 -r 59aab666f2bf scripts/optimization/fsolve.m --- a/scripts/optimization/fsolve.m Sat Feb 18 11:59:21 2012 -0800 +++ b/scripts/optimization/fsolve.m Sat Feb 18 12:43:46 2012 -0800 @@ -450,6 +450,8 @@ error ("fsolve:notnum", "fsolve: non-numeric value encountered"); elseif (any (isnan (fx(:)))) error ("fsolve:isnan", "fsolve: NaN value encountered"); + elseif (any (isinf (fx(:)))) + error ("fsolve:isinf", "fsolve: Inf value encountered"); endif endfunction