From 547ec34e0bf790a961d907c9c45bc207d5723d44 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 20 Jul 2013 18:54:16 +0200 Subject: [PATCH] RootFinding: FindRoots functions with optional maxIterations argument --- src/Numerics/FindRoots.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Numerics/FindRoots.cs b/src/Numerics/FindRoots.cs index 1dd1a80d..d92db9b9 100644 --- a/src/Numerics/FindRoots.cs +++ b/src/Numerics/FindRoots.cs @@ -35,16 +35,16 @@ namespace MathNet.Numerics { public static class FindRoots { - public static double OfFunction(Func f, double lowerBound, double upperBound, double accuracy = 1e-8) + public static double OfFunction(Func f, double lowerBound, double upperBound, double accuracy = 1e-8, int maxIterations = 100) { double root; - if (Brent.TryFindRoot(f, lowerBound, upperBound, accuracy, 100, out root)) + if (Brent.TryFindRoot(f, lowerBound, upperBound, accuracy, maxIterations, out root)) { return root; } - if (Bisection.TryFindRoot(f, lowerBound, upperBound, accuracy, 100, out root)) + if (Bisection.TryFindRoot(f, lowerBound, upperBound, accuracy, maxIterations, out root)) { return root; } @@ -52,16 +52,16 @@ namespace MathNet.Numerics throw new NonConvergenceException("The algorithm has failed or exceeded the number of iterations allowed"); } - public static double OfFunctionAndDerivative(Func f, Func df, double lowerBound, double upperBound, double accuracy = 1e-8) + public static double OfFunctionAndDerivative(Func f, Func df, double lowerBound, double upperBound, double accuracy = 1e-8, int maxIterations = 100) { double root; - if (RobustNewtonRaphson.TryFindRoot(f, df, lowerBound, upperBound, accuracy, 100, 20, out root)) + if (RobustNewtonRaphson.TryFindRoot(f, df, lowerBound, upperBound, accuracy, maxIterations, 20, out root)) { return root; } - if (Bisection.TryFindRoot(f, lowerBound, upperBound, accuracy, 100, out root)) + if (Bisection.TryFindRoot(f, lowerBound, upperBound, accuracy, maxIterations, out root)) { return root; }