ZeroDivisionError in broyden1 when initial guess is the right answer. #3227
Labels
defect
A clear bug or issue that prevents SciPy from being installed or used as expected
good first issue
Good topic for first contributor pull requests, with a relatively straightforward solution
scipy.optimize
Milestone
I'm getting a ZeroDivisionError when I use
scipy.optimize.broyden1
and the initial guess happens to be the right answer already -- not so uncommon a situation in real life, so I'm kind of surprised that this issue hasn't been reported already. Anyway, here is a code snippet to reproduce the problem:I'm using scipy version 0.13.2 with Mac OS 10.6.8 (using the fink installation of scipy-py27), and I get the following output:
I think the fix is trivial. Just check if
norm(f0) == 0
, and set alpha to 1 (or whatever) in that case.The workaround until this is fixed is to make sure to set alpha to something reasonable. Passing
alpha=1
tobroyden1
works just fine in this case.The text was updated successfully, but these errors were encountered: