Skip to content

Commit

Permalink
RootFinding: cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrnet committed May 1, 2013
1 parent a177228 commit 65cfd6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Numerics/RootFinding/BrentRootFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
38 changes: 13 additions & 25 deletions src/Numerics/RootFinding/RootFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, double> _func;
//protected Func<double, double> 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<double, double> _func;
private double bracketingFactor = 1.6;
private double _bracketingFactor = 1.6;

/// <summary>Constructor.</summary>
/// <param name="f">A continuous function.</param>
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; } }

Expand All @@ -43,15 +33,19 @@ public Func<double, double> 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
Expand All @@ -61,12 +55,6 @@ public int Iterations
}
protected get { return _maxNumIters; }
}
public double Accuracy
{
get { return _accuracy; }
set { _accuracy = value; }
}
#endregion Properties

/// <summary>Detect a range containing at least one root.</summary>
/// <param name="xmin">Lower value of the range.</param>
Expand Down

0 comments on commit 65cfd6c

Please sign in to comment.