diff --git a/src/Numerics/RootFinding/BrentRootFinder.cs b/src/Numerics/RootFinding/BrentRootFinder.cs index 364cf333e..2241a61fa 100644 --- a/src/Numerics/RootFinding/BrentRootFinder.cs +++ b/src/Numerics/RootFinding/BrentRootFinder.cs @@ -54,7 +54,7 @@ University Press fxmax = fxmin; } // Convergence check - xAcc1 = 2.0 * DOUBLE_ACCURACY * Math.Abs(root) + 0.5 * Accuracy; + xAcc1 = 2.0 * DoubleAccuracy * Math.Abs(root) + 0.5 * Accuracy; xMid = (xmax - root) / 2.0; if (Math.Abs(xMid) <= xAcc1 || Close(froot, 0.0)) { diff --git a/src/Numerics/RootFinding/RootFinder.cs b/src/Numerics/RootFinding/RootFinder.cs index 8fe6540d5..024bcac41 100644 --- a/src/Numerics/RootFinding/RootFinder.cs +++ b/src/Numerics/RootFinding/RootFinder.cs @@ -5,36 +5,26 @@ namespace MathNet.Numerics.RootFinding { public abstract class RootFinder { - protected const double DOUBLE_ACCURACY = 9.99200722162641E-16; - private const int DEFAULT_MAX_ITERATIONS = 30; - private const double DEFAULT_ACCURACY = 1e-8; - - //protected int _maxNumIters; - //protected double _xmin = double.MinValue; - //protected double _xmax = double.MaxValue; - //protected double _accuracy; - //protected Func _func; - //protected Func m_Of; + protected const double DoubleAccuracy = 9.99200722162641E-16; + private const int DefaultMaxIterations = 30; + private const double DefaultAccuracy = 1e-8; + int _maxNumIters; double _xmin = double.MinValue; double _xmax = double.MaxValue; - double _accuracy; Func _func; - private double bracketingFactor = 1.6; + private double _bracketingFactor = 1.6; - /// Constructor. - /// A continuous function. - public RootFinder() : this(DEFAULT_MAX_ITERATIONS, DEFAULT_ACCURACY) + public RootFinder() : this(DefaultMaxIterations, DefaultAccuracy) { } public RootFinder(int numIters, double accuracy) { _maxNumIters = numIters; - _accuracy = accuracy; + Accuracy = accuracy; } - #region Properties protected double XMin { get { return _xmin; } } protected double XMax { get { return _xmax; } } @@ -43,15 +33,19 @@ public Func Func get { return _func; } set { _func = value; } } + + public double Accuracy { get; set; } + public double BracketingFactor { - get { return bracketingFactor; } + get { return _bracketingFactor; } set { if (value <= 0.0) throw new ArgumentOutOfRangeException(); - bracketingFactor = value; + _bracketingFactor = value; } } + public int Iterations { set @@ -61,12 +55,6 @@ public int Iterations } protected get { return _maxNumIters; } } - public double Accuracy - { - get { return _accuracy; } - set { _accuracy = value; } - } - #endregion Properties /// Detect a range containing at least one root. /// Lower value of the range.