octave-maintainers
[Top][All Lists]
Advanced

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

Re: Exit codes for fzero


From: Jaroslav Hajek
Subject: Re: Exit codes for fzero
Date: Fri, 19 Feb 2010 12:04:00 +0100

On Thu, Feb 18, 2010 at 5:09 PM, Rik <address@hidden> wrote:
>
>>
>> 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

I applied the change, along with one minor modification: I used -5 as
the return code to stay Matlab-compatible.
http://hg.savannah.gnu.org/hgweb/octave/rev/7c97da90fc8f

thx

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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