From 0952f5145a81b87da61b8b4185eee66492d0d82f Mon Sep 17 00:00:00 2001 From: Scott Stephens Date: Tue, 12 Nov 2013 17:33:25 -0600 Subject: [PATCH] Optimization: Fix bug in BisectionRootFinder * Algorithm would incorrectly exit with MaximumIterationsException if the root was bounded on the last permissible expansion step. --- src/Numerics/Optimization/BisectionRootFinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Numerics/Optimization/BisectionRootFinder.cs b/src/Numerics/Optimization/BisectionRootFinder.cs index 5d541306..d3c196cb 100644 --- a/src/Numerics/Optimization/BisectionRootFinder.cs +++ b/src/Numerics/Optimization/BisectionRootFinder.cs @@ -59,7 +59,7 @@ namespace MathNet.Numerics.Optimization expansion_steps += 1; } - if (expansion_steps == this.MaxExpansionSteps) + if (Math.Sign(lower_val) == Math.Sign(upper_val) && expansion_steps == this.MaxExpansionSteps) throw new MaximumIterationsException("Could not bound root in maximum expansion iterations."); while (Math.Abs(upper_val - lower_val) > 0.5 * this.ObjectiveTolerance || Math.Abs(upper_bound - lower_bound) > 0.5 * this.XTolerance)