Browse Source

RootFinding: simplify exception

pull/121/head
Christoph Ruegg 13 years ago
parent
commit
2d4ac98a29
  1. 1
      src/Numerics/Numerics.csproj
  2. 2
      src/Numerics/RootFinding/BrentRootFinder.cs
  3. 45
      src/Numerics/RootFinding/RootFinder.cs
  4. 21
      src/Numerics/RootFinding/RootFindingException.cs

1
src/Numerics/Numerics.csproj

@ -111,6 +111,7 @@
<Compile Include="LinearAlgebra\Generic\Vector.BCL.cs" />
<Compile Include="RootFinding\BrentRootFinder.cs" />
<Compile Include="RootFinding\RootFinder.cs" />
<Compile Include="RootFinding\RootFindingException.cs" />
<Compile Include="SpecialFunctions\Evaluate.cs" />
<Compile Include="SpecialFunctions\ModifiedStruve.cs" />
<Compile Include="SpecialFunctions\ModifiedBessel.cs" />

2
src/Numerics/RootFinding/BrentRootFinder.cs

@ -109,7 +109,7 @@ namespace MathNet.Numerics.RootFinding
}
// The algorithm has exceeded the number of iterations allowed
throw new RootFinderException(Resources.AccuracyNotReached, i, new Range(XMin, XMax), Math.Abs(xMid));
throw new RootFindingException(Resources.AccuracyNotReached, i, XMin, XMax, Math.Abs(xMid));
}
}
}

45
src/Numerics/RootFinding/RootFinder.cs

@ -3,44 +3,7 @@ using MathNet.Numerics.Properties;
namespace MathNet.Numerics.RootFinding
{
public struct Range
{
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
public abstract class RootFinder
{
protected const double DOUBLE_ACCURACY = 9.99200722162641E-16;
private const int DEFAULT_MAX_ITERATIONS = 30;
@ -59,8 +22,6 @@ namespace MathNet.Numerics.RootFinding
Func<double, double> _func;
private double bracketingFactor = 1.6;
/// <summary>Constructor.</summary>
/// <param name="f">A continuous function.</param>
public RootFinder() : this(DEFAULT_MAX_ITERATIONS, DEFAULT_ACCURACY)
@ -117,7 +78,7 @@ namespace MathNet.Numerics.RootFinding
{
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);
@ -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>

21
src/Numerics/RootFinding/RootFindingException.cs

@ -0,0 +1,21 @@
using System;
namespace MathNet.Numerics.RootFinding
{
public class RootFindingException : Exception
{
public RootFindingException(string message, int iteration, double rangeMin, double rangeMax, double accuracy)
: base(message)
{
Iteration = iteration;
RangeMin = rangeMin;
RangeMax = rangeMax;
Accuracy = accuracy;
}
public int Iteration { get; set; }
public double RangeMin { get; set; }
public double RangeMax { get; set; }
public double Accuracy { set; get; }
}
}
Loading…
Cancel
Save