|
|
@ -3,44 +3,7 @@ using MathNet.Numerics.Properties; |
|
|
|
|
|
|
|
|
namespace MathNet.Numerics.RootFinding |
|
|
namespace MathNet.Numerics.RootFinding |
|
|
{ |
|
|
{ |
|
|
public struct Range |
|
|
public abstract class RootFinder |
|
|
{ |
|
|
|
|
|
double Min, Max; |
|
|
|
|
|
|
|
|
|
|
|
public Range(double min, double max) |
|
|
|
|
|
{ |
|
|
|
|
|
Min = min; Max = max; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public class RootFinderException : Exception |
|
|
|
|
|
{ |
|
|
|
|
|
private int m_Iteration; |
|
|
|
|
|
private Range m_Range; |
|
|
|
|
|
private double m_Accuracy; |
|
|
|
|
|
|
|
|
|
|
|
public RootFinderException(string message, int iteration, Range range, double accuracy) |
|
|
|
|
|
: base(message) |
|
|
|
|
|
{ |
|
|
|
|
|
m_Iteration = iteration; |
|
|
|
|
|
m_Range = range; |
|
|
|
|
|
m_Accuracy = accuracy; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int Iteration |
|
|
|
|
|
{ |
|
|
|
|
|
get { return m_Iteration; } |
|
|
|
|
|
set { m_Iteration = value; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Range Range |
|
|
|
|
|
{ |
|
|
|
|
|
get { return m_Range; } |
|
|
|
|
|
set { m_Range = value; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public double Accuracy { set; get; } |
|
|
|
|
|
} |
|
|
|
|
|
public abstract class RootFinder |
|
|
|
|
|
{ |
|
|
{ |
|
|
protected const double DOUBLE_ACCURACY = 9.99200722162641E-16; |
|
|
protected const double DOUBLE_ACCURACY = 9.99200722162641E-16; |
|
|
private const int DEFAULT_MAX_ITERATIONS = 30; |
|
|
private const int DEFAULT_MAX_ITERATIONS = 30; |
|
|
@ -59,8 +22,6 @@ namespace MathNet.Numerics.RootFinding |
|
|
Func<double, double> _func; |
|
|
Func<double, double> _func; |
|
|
private double bracketingFactor = 1.6; |
|
|
private double bracketingFactor = 1.6; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Constructor.</summary>
|
|
|
/// <summary>Constructor.</summary>
|
|
|
/// <param name="f">A continuous function.</param>
|
|
|
/// <param name="f">A continuous function.</param>
|
|
|
public RootFinder() : this(DEFAULT_MAX_ITERATIONS, DEFAULT_ACCURACY) |
|
|
public RootFinder() : this(DEFAULT_MAX_ITERATIONS, DEFAULT_ACCURACY) |
|
|
@ -117,7 +78,7 @@ namespace MathNet.Numerics.RootFinding |
|
|
{ |
|
|
{ |
|
|
if (xmin >= xmax) |
|
|
if (xmin >= xmax) |
|
|
{ |
|
|
{ |
|
|
throw new RootFinderException(string.Format(Resources.ArgumentOutOfRangeGreater,"xmax","xmin"), 0, new Range(xmin, xmax), 0.0); |
|
|
throw new RootFindingException(string.Format(Resources.ArgumentOutOfRangeGreater,"xmax","xmin"), 0, xmin, xmax, 0.0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double fmin = _func(xmin); |
|
|
double fmin = _func(xmin); |
|
|
@ -139,7 +100,7 @@ namespace MathNet.Numerics.RootFinding |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
throw new RootFinderException(Resources.RootNotFound, i, new Range(fmin, fmax), 0.0); |
|
|
throw new RootFindingException(Resources.RootNotFound, i, fmin, fmax, 0.0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>Prototype algorithm for solving the equation f(x)=0.</summary>
|
|
|
/// <summary>Prototype algorithm for solving the equation f(x)=0.</summary>
|
|
|
|