[SciPy-User] optimize.brentq and step function

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Mar 1 00:20:30 EST 2013


On Thu, Feb 28, 2013 at 11:57 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
>
> On Thu, Feb 28, 2013 at 9:43 PM, Charles R Harris
> <charlesr.harris at gmail.com> wrote:
>>
>>
>>
>> On Thu, Feb 28, 2013 at 8:44 PM, <josef.pktd at gmail.com> wrote:
>>>
>>> brentq documentation says "f must be a continuous function"
>>>
>>> I forgot that I have a step function and tried brentq and it worked.
>>> Is this an accident or a feature?
>>>
>>
>> Feature, the documentation is off. Brentq falls back on bisection when it
>> converges too slowly. And there is some subtlety in 'slowly', but it does
>> work find a point of sign where the function changes sign, all that is
>> required is the the function be defined everywhere on the interval and there
>> be a finite number of 'zeros'. If you know you have a discontinuity, plain
>> old bisection is probably faster, but one of the best things about brentq is
>> its generality.
>
>
> And the finite part is wrong. Bisection will always find a `zero` if the
> ends have opposite signs since the interval is halved on every iteration and
> it will terminate when the interval is sufficiently small. But all you know
> at that point is that the ends have different signs, not that the function
> is almost zero there. So continuity is required for the function to actually
> be close to zero.

Thanks for the explanation, all clear.
I also tried optimize.bisect with similar results as brentq.

Related: Is there a general interest in an integer bisection? function
possibly defined only at integer points

There is one in stats.distributions, I fixed it, but I haven't read
anything about bisections (at least not since college).

Josef

>
> Chuck
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list