From 42731600ed1d1efb37b81471437d46af52eee145 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 20 Jul 2013 18:52:07 +0200 Subject: [PATCH] RootFinding: OfFunctionAndDerivative fall back to Bisection instead of Brent (more robust) --- src/Numerics/FindRoots.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Numerics/FindRoots.cs b/src/Numerics/FindRoots.cs index deef6948..1dd1a80d 100644 --- a/src/Numerics/FindRoots.cs +++ b/src/Numerics/FindRoots.cs @@ -38,6 +38,7 @@ namespace MathNet.Numerics public static double OfFunction(Func f, double lowerBound, double upperBound, double accuracy = 1e-8) { double root; + if (Brent.TryFindRoot(f, lowerBound, upperBound, accuracy, 100, out root)) { return root; @@ -54,11 +55,13 @@ namespace MathNet.Numerics public static double OfFunctionAndDerivative(Func f, Func df, double lowerBound, double upperBound, double accuracy = 1e-8) { double root; + if (RobustNewtonRaphson.TryFindRoot(f, df, lowerBound, upperBound, accuracy, 100, 20, out root)) { return root; } - if (Brent.TryFindRoot(f, lowerBound, upperBound, accuracy, 100, out root)) + + if (Bisection.TryFindRoot(f, lowerBound, upperBound, accuracy, 100, out root)) { return root; }