octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exit codes for fzero


From: Rik
Subject: Re: Exit codes for fzero
Date: Thu, 18 Feb 2010 11:09:56 -0500 (EST)

>
> What about the following? Just compare the final slope relatively to
> the starting one. This should achieve scaling-independency in both x
> and f.
>
> # HG changeset patch
> # User Jaroslav Hajek <address@hidden>
> # Date 1266405408 -3600
> # Node ID 11bdf1fec1aacbdbf5844aa9583888fdcee8e4df
> # Parent  83fa590b8a09d9318b3c649901e156717d9a6c2a
> [mq]: patch.fzero
>
> diff --git a/scripts/optimization/fzero.m
> b/scripts/optimization/fzero.m
> --- a/scripts/optimization/fzero.m
> +++ b/scripts/optimization/fzero.m
> @@ -38,6 +38,8 @@
>  ## Maximum number of iterations or function evaluations has been
> exhausted.
>  ## @item -1
>  ## The algorithm has been terminated from user output function.
> +## @item -2
> +## The algorithm may have converged to a singular point.
>  ## @end itemize
>  ## @seealso{optimset, fsolve}
>  ## @end deftypefn
> @@ -133,6 +135,8 @@
>      error ("fzero:bracket", "fzero: not a valid initial bracketing");
>    endif
>
> +  slope0 = (fb - fa) / (b - a);
> +
>    itype = 1;
>
>    if (abs (fa) < abs (fb))
> @@ -281,6 +285,13 @@
>      endif
>    endwhile
>
> +  ## Check solution for a singularity by examining slope
> +  if (info == 1)
> +    if ((b - a) != 0 && abs ((fb - fa)/(b - a) / slope0) > max (1e6,
> 0.5/tolx))
> +      info = -2;
> +    endif
> +  endif
> +
>    output.iterations = niter;
>    output.funcCount = nfev;
>    output.bracket = [a, b];
>
>
> this classifies correctly your example as well as the one that fools
> Matlab.
>
> what do you think?
2/18/10

Jaroslav,

This looks good.  Unfortunately my computer died yesterday.  I would
say go ahead and commit this or if you would like me to do it I will
take care of it in a week when I get my new box.

--Rik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]