Browse Source

Minor clean-up.

pull/749/head
Febin 6 years ago
parent
commit
054292fe31
  1. 10
      src/Numerics.Tests/InterpolationTests/PchipSplineTest.cs
  2. 6
      src/Numerics/Interpolation/CubicSpline.cs

10
src/Numerics.Tests/InterpolationTests/PchipSplineTest.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -38,8 +38,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
readonly double[] _t = { -2.0, -1.0, 0.0, 1.0, 2.0 };
readonly double[] _y = { 1.0, 2.0, -1.0, 0.0, 1.0 };
readonly double[] _tNag = new double[] { 7.99, 8.09, 8.19, 8.70, 9.20, 10.00, 12.00, 15.00, 20.00 };
readonly double[] _yNag = new double[] { 0.00000E+0, 0.27643E-4, 0.43750E-1, 0.16918E+0, 0.46943E+0, 0.94374E+0, 0.99864E+0, 0.99992E+0, 0.99999E+0 };
readonly double[] _tNag = { 7.99, 8.09, 8.19, 8.70, 9.20, 10.00, 12.00, 15.00, 20.00 };
readonly double[] _yNag = { 0.00000E+0, 0.27643E-4, 0.43750E-1, 0.16918E+0, 0.46943E+0, 0.94374E+0, 0.99864E+0, 0.99992E+0, 0.99999E+0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -94,7 +94,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[TestCase(17.5980, 1.0000, 5e-5)]
[TestCase(18.7990, 1.0000, 5e-5)]
[TestCase(20.0000, 1.0000, 5e-5)]
public void FitsAtExamplePoints(double t, double x, double maxAbsoluteError)
public void FitsAtNagExamplePoints(double t, double x, double maxAbsoluteError)
{
IInterpolation it = CubicSpline.InterpolatePchip(_tNag, _yNag);
@ -124,7 +124,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.That(() => CubicSpline.InterpolatePchip(new double[0], new double[0]), Throws.ArgumentException);
Assert.That(() => CubicSpline.InterpolatePchip(new double[2], new double[2]), Throws.ArgumentException);
Assert.That(CubicSpline.InterpolatePchip(new[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, new[] { 2.0, 2.0, 2.0, 2.0, 2.0 }).Interpolate(1.0), Is.EqualTo(2.0));
Assert.That(CubicSpline.InterpolatePchip(new[] { 1.0, 2.0, 3.0 }, new[] { 2.0, 2.0, 2.0 }).Interpolate(1.0), Is.EqualTo(2.0));
}
}
}

6
src/Numerics/Interpolation/CubicSpline.cs

@ -259,7 +259,8 @@ namespace MathNet.Numerics.Interpolation
// Special case end-points.
dd[0] = PchipEndPoints(x[1] - x[0], x[2] - x[1], m[0], m[1]);
dd[dd.Length - 1] = PchipEndPoints(x[x.Length - 1] - x[x.Length - 2], x[x.Length - 2] - x[x.Length - 3],
dd[dd.Length - 1] = PchipEndPoints(
x[x.Length - 1] - x[x.Length - 2], x[x.Length - 2] - x[x.Length - 3],
m[m.Length - 1], m[m.Length - 2]);
return InterpolateHermiteSorted(x, y, dd);
@ -267,7 +268,7 @@ namespace MathNet.Numerics.Interpolation
static double PchipEndPoints(double h0, double h1, double m0, double m1)
{
// One-sided three-point estimate for the derivative.
// One-sided, shape-preserving, three-point estimate for the derivative.
var d = ((2 * h0 + h1) * m0 - h0 * m1) / (h0 + h1);
if (Math.Sign(d) != Math.Sign(m0))
@ -279,7 +280,6 @@ namespace MathNet.Numerics.Interpolation
return d;
}
/// <summary>
/// Create a piecewise cubic Hermite interpolating polynomial from an unsorted set of (x,y) value pairs.
/// Monotone-preserving interpolation with continuous first derivative.

Loading…
Cancel
Save