Status: New
Owner: ----
New issue 233 by
smi...@gmail.com: bisect fails if root is at midpoint of
initial range
http://code.google.com/p/mpmath/issues/detail?id=233
What steps will reproduce the problem?
1. findroot(x**2-1,(0,2),solver='bisect')
What is the expected output? What do you see instead?
mpf('1.0')
The following patch will fix the problem. Illinois and Ridder already
detect "flat functions" and return in this situation so it's not a problem
for them. An alternative to the patch below is just to make Bisection
return in the same way as Illinois and Ridder.
--- a/sympy/mpmath/calculus/optimization.py
+++ b/sympy/mpmath/calculus/optimization.py
@@ -320,11 +320,14 @@ def __iter__(self):
while True:
m = self.ctx.ldexp(a + b, -1)
fm = f(m)
- if fm * fb < 0:
+ sign = fm * fb
+ if sign < 0:
a = m
- else:
+ elif sign > 0:
b = m
fb = fm
+ else:
+ yield m, 0
l /= 2
yield (a + b)/2, abs(l)