Browse Source

Interpolation: api cleanup

pull/194/head
Christoph Ruegg 13 years ago
parent
commit
3aca1f4bf7
  1. 16
      src/Numerics/Interpolate.cs
  2. 16
      src/Numerics/Interpolation/CubicSpline.cs
  3. 12
      src/UnitTests/InterpolationTests/CubicSplineTest.cs

16
src/Numerics/Interpolate.cs

@ -71,14 +71,14 @@ namespace MathNet.Numerics
/// <summary>
/// Create a burlisch stoer rational interpolation based on arbitrary points.
/// </summary>
/// <param name="points">The sample points t. Supports both lists and arrays.</param>
/// <param name="values">The sample point values x(t). Supports both lists and arrays.</param>
/// <param name="points">The sample points t. Optimized for arrays..</param>
/// <param name="values">The sample point values x(t). Optimized for arrays.</param>
/// <returns>
/// An interpolation scheme optimized for the given sample points and values,
/// which can then be used to compute interpolations and extrapolations
/// on arbitrary points.
/// </returns>
public static IInterpolation RationalWithPoles(IList<double> points, IList<double> values)
public static IInterpolation RationalWithPoles(IEnumerable<double> points, IEnumerable<double> values)
{
return new BulirschStoerRationalInterpolation(points, values);
}
@ -107,14 +107,14 @@ namespace MathNet.Numerics
/// If the points happen to be equidistant, consider to use the much more robust PolynomialEquidistant instead.
/// Otherwise, consider whether RationalWithoutPoles would not be a more robust alternative.
/// </summary>
/// <param name="points">The sample points t. Supports both lists and arrays.</param>
/// <param name="values">The sample point values x(t). Supports both lists and arrays.</param>
/// <param name="points">The sample points t. Optimized for arrays.</param>
/// <param name="values">The sample point values x(t). Optimized for arrays.</param>
/// <returns>
/// An interpolation scheme optimized for the given sample points and values,
/// which can then be used to compute interpolations and extrapolations
/// on arbitrary points.
/// </returns>
public static IInterpolation Polynomial(IList<double> points, IList<double> values)
public static IInterpolation Polynomial(IEnumerable<double> points, IEnumerable<double> values)
{
return new NevillePolynomialInterpolation(points, values);
}
@ -139,7 +139,7 @@ namespace MathNet.Numerics
}
/// <summary>
/// Create an piecewise cubic spline interpolation based on arbitrary points, with zero secondary derivatives at the boundaries.
/// Create an piecewise natural cubic spline interpolation based on arbitrary points, with zero secondary derivatives at the boundaries.
/// </summary>
/// <param name="points">The sample points t. Optimized for arrays.</param>
/// <param name="values">The sample point values x(t). Optimized for arrays.</param>
@ -154,7 +154,7 @@ namespace MathNet.Numerics
/// </remarks>
public static IInterpolation CubicSpline(IEnumerable<double> points, IEnumerable<double> values)
{
return Interpolation.CubicSpline.Interpolate(points, values);
return Interpolation.CubicSpline.InterpolateNatural(points, values);
}
/// <summary>

16
src/Numerics/Interpolation/CubicSpline.cs

@ -170,11 +170,25 @@ namespace MathNet.Numerics.Interpolation
return InterpolateHermite(xx, yy, dd);
}
public static CubicSpline Interpolate(IEnumerable<double> x, IEnumerable<double> y)
/// <summary>
/// Create a natural cubic spline interpolation from a set of (x,y) value pairs and zero second derivatives at the two boundaries.
/// </summary>
/// <remarks>
/// The value pairs do not have to be sorted, but if they are not sorted ascendingly
/// and the passed x and y arguments are arrays, they will be sorted inplace and thus modified.
/// </remarks>
public static CubicSpline InterpolateNatural(IEnumerable<double> x, IEnumerable<double> y)
{
return InterpolateBoundaries(x, y, SplineBoundaryCondition.SecondDerivative, 0.0, SplineBoundaryCondition.SecondDerivative, 0.0);
}
/// <summary>
/// Create a cubic spline interpolation from a set of (x,y) value pairs and custom boundary/termination conditions.
/// </summary>
/// <remarks>
/// The value pairs do not have to be sorted, but if they are not sorted ascendingly
/// and the passed x and y arguments are arrays, they will be sorted inplace and thus modified.
/// </remarks>
public static CubicSpline InterpolateBoundaries(IEnumerable<double> x, IEnumerable<double> y,
SplineBoundaryCondition leftBoundaryCondition, double leftBoundary,
SplineBoundaryCondition rightBoundaryCondition, double rightBoundary)

12
src/UnitTests/InterpolationTests/CubicSplineTest.cs

@ -45,7 +45,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[Test]
public void NaturalFitsAtSamplePoints()
{
IInterpolation it = CubicSpline.Interpolate(_t, _y);
IInterpolation it = CubicSpline.InterpolateNatural(_t, _y);
for (int i = 0; i < _y.Length; i++)
{
Assert.AreEqual(_y[i], it.Interpolate(_t[i]), "A Exact Point " + i);
@ -72,9 +72,9 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[TestCase(1.2, .30285714285714285716, 1e-15)]
[TestCase(10.0, 189, 1e-15)]
[TestCase(-10.0, 677, 1e-12)]
public void NaturalFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
public void NaturalFitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
{
IInterpolation it = CubicSpline.Interpolate(_t, _y);
IInterpolation it = CubicSpline.InterpolateNatural(_t, _y);
Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
}
@ -111,7 +111,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[TestCase(1.2, .4148571428571428571, 1e-15)]
[TestCase(10.0, -608.14285714285714286, 1e-12)]
[TestCase(-10.0, 1330.1428571428571429, 1e-12)]
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
public void FixedFirstDerivativeFitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
{
IInterpolation it = CubicSpline.InterpolateBoundaries(_t, _y, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0);
Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[TestCase(1.2, .31771428571428571421, 1e-15)]
[TestCase(10.0, 39, 1e-13)]
[TestCase(-10.0, -37, 1e-12)]
public void FixedSecondDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
public void FixedSecondDerivativeFitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
{
IInterpolation it = CubicSpline.InterpolateBoundaries(_t, _y, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0);
Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
@ -167,7 +167,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);
IInterpolation it = CubicSpline.Interpolate(x, y);
IInterpolation it = CubicSpline.InterpolateNatural(x, y);
for (int i = 0; i < xtest.Length; i++)
{
Assert.AreEqual(ytest[i], it.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i);

Loading…
Cancel
Save