Browse Source

Interpolation: computing interpolation 1st/2nd derivative at once should use tuple type instead of out parameters

optimization-1
Christoph Ruegg 13 years ago
parent
commit
9af57cf3d6
  1. 6
      src/Numerics/Interpolate.cs
  2. 15
      src/Numerics/Interpolation/AkimaSplineInterpolation.cs
  3. 17
      src/Numerics/Interpolation/BarycentricInterpolation.cs
  4. 17
      src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
  5. 15
      src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs
  6. 15
      src/Numerics/Interpolation/CubicSplineInterpolation.cs
  7. 17
      src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs
  8. 17
      src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs
  9. 15
      src/Numerics/Interpolation/IInterpolation.cs
  10. 15
      src/Numerics/Interpolation/LinearSplineInterpolation.cs
  11. 31
      src/Numerics/Interpolation/NevillePolynomialInterpolation.cs
  12. 30
      src/Numerics/Interpolation/SplineInterpolation.cs
  13. 14
      src/UnitTests/InterpolationTests/AkimaSplineTest.cs
  14. 41
      src/UnitTests/InterpolationTests/CubicSplineTest.cs
  15. 17
      src/UnitTests/InterpolationTests/LinearSplineTest.cs
  16. 12
      src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

6
src/Numerics/Interpolate.cs

@ -69,7 +69,7 @@ namespace MathNet.Numerics
IList<double> points,
IList<double> values)
{
LinearSplineInterpolation method = new LinearSplineInterpolation();
var method = new LinearSplineInterpolation();
method.Initialize(points, values);
return method;
}
@ -88,7 +88,7 @@ namespace MathNet.Numerics
IList<double> points,
IList<double> values)
{
FloaterHormannRationalInterpolation method = new FloaterHormannRationalInterpolation();
var method = new FloaterHormannRationalInterpolation();
method.Initialize(points, values);
return method;
}
@ -107,7 +107,7 @@ namespace MathNet.Numerics
IList<double> points,
IList<double> values)
{
BulirschStoerRationalInterpolation method = new BulirschStoerRationalInterpolation();
var method = new BulirschStoerRationalInterpolation();
method.Initialize(points, values);
return method;
}

15
src/Numerics/Interpolation/AkimaSplineInterpolation.cs

@ -72,7 +72,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return true; }
@ -249,27 +249,22 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t)
{
return _spline.Differentiate(t);
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
public double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
public Tuple<double, double, double> DifferentiateAll(double t)
{
return _spline.Differentiate(t, out interpolatedValue, out secondDerivative);
return _spline.DifferentiateAll(t);
}
/// <summary>

17
src/Numerics/Interpolation/BarycentricInterpolation.cs

@ -81,7 +81,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return false; }
@ -203,36 +203,31 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Differentiate at point t.
/// Differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
double IInterpolation.Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Integrate up to point t.
/// Integrate up to point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>

17
src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs

@ -76,7 +76,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return false; }
@ -187,36 +187,31 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Differentiate at point t.
/// Differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
double IInterpolation.Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Integrate up to point t.
/// Integrate up to point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>

15
src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs

@ -74,7 +74,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return true; }
@ -183,27 +183,22 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t)
{
return _spline.Differentiate(t);
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
public double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
public Tuple<double, double, double> DifferentiateAll(double t)
{
return _spline.Differentiate(t, out interpolatedValue, out secondDerivative);
return _spline.DifferentiateAll(t);
}
/// <summary>

15
src/Numerics/Interpolation/CubicSplineInterpolation.cs

@ -103,7 +103,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return true; }
@ -383,27 +383,22 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t)
{
return _spline.Differentiate(t);
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
public double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
public Tuple<double, double, double> DifferentiateAll(double t)
{
return _spline.Differentiate(t, out interpolatedValue, out secondDerivative);
return _spline.DifferentiateAll(t);
}
/// <summary>

17
src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs

@ -86,7 +86,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return false; }
@ -189,36 +189,31 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Differentiate at point t.
/// Differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
double IInterpolation.Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Integrate up to point t.
/// Integrate up to point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>

17
src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs

@ -89,7 +89,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return false; }
@ -266,36 +266,31 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Differentiate at point t.
/// Differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double, out double, out double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
double IInterpolation.Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{
throw new NotSupportedException();
}
/// <summary>
/// Integrate up to point t.
/// Integrate up to point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>

15
src/Numerics/Interpolation/IInterpolation.cs

@ -28,6 +28,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
@ -39,7 +41,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool SupportsDifferentiation { get; }
/// <summary>
@ -61,22 +63,17 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
double Differentiate(double t);
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative);
Tuple<double, double, double> DifferentiateAll(double t);
/// <summary>
/// Integrate up to point t.

15
src/Numerics/Interpolation/LinearSplineInterpolation.cs

@ -72,7 +72,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return true; }
@ -167,27 +167,22 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t)
{
return _spline.Differentiate(t);
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
public double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
public Tuple<double, double, double> DifferentiateAll(double t)
{
return _spline.Differentiate(t, out interpolatedValue, out secondDerivative);
return _spline.DifferentiateAll(t);
}
/// <summary>

31
src/Numerics/Interpolation/NevillePolynomialInterpolation.cs

@ -82,7 +82,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return true; }
@ -164,7 +164,7 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t)
{
double[] x = new double[_values.Count];
@ -187,22 +187,17 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
public double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
public Tuple<double, double, double> DifferentiateAll(double t)
{
double[] x = new double[_values.Count];
double[] dx = new double[_values.Count];
double[] ddx = new double[_values.Count];
var x = new double[_values.Count];
var dx = new double[_values.Count];
var ddx = new double[_values.Count];
_values.CopyTo(x, 0);
for (int level = 1; level < x.Length; level++)
@ -212,19 +207,17 @@ namespace MathNet.Numerics.Interpolation
double hp = t - _points[i + level];
double ho = _points[i] - t;
double den = _points[i] - _points[i + level];
ddx[i] = ((hp*ddx[i]) + (ho*ddx[i + 1]) + (2*dx[i]) - (2*dx[i + 1]))/den;
dx[i] = ((hp*dx[i]) + x[i] + (ho*dx[i + 1]) - x[i + 1])/den;
x[i] = ((hp*x[i]) + (ho*x[i + 1]))/den;
ddx[i] = ((hp * ddx[i]) + (ho * ddx[i + 1]) + (2 * dx[i]) - (2 * dx[i + 1])) / den;
dx[i] = ((hp * dx[i]) + x[i] + (ho * dx[i + 1]) - x[i + 1]) / den;
x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den;
}
}
interpolatedValue = x[0];
secondDerivative = ddx[0];
return dx[0];
return new Tuple<double, double, double>(x[0], dx[0], ddx[0]);
}
/// <summary>
/// Integrate up to point t.
/// Integrate up to point t. NOT SUPPORTED.
/// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>

30
src/Numerics/Interpolation/SplineInterpolation.cs

@ -80,7 +80,7 @@ namespace MathNet.Numerics.Interpolation
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation
{
get { return true; }
@ -158,7 +158,7 @@ namespace MathNet.Numerics.Interpolation
/// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double, out double, out double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t)
{
int closestLeftIndex = IndexOfClosestPointLeftOf(t);
@ -173,36 +173,22 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Differentiate at point t.
/// Interpolate, differentiate and 2nd differentiate at point t.
/// </summary>
/// <param name="t">Point t to interpolate at.</param>
/// <param name="interpolatedValue">Interpolated value x(t)</param>
/// <param name="secondDerivative">Interpolated second derivative at point t.</param>
/// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="Differentiate(double)"/>
public double Differentiate(
double t,
out double interpolatedValue,
out double secondDerivative)
public Tuple<double, double, double> DifferentiateAll(double t)
{
int closestLeftIndex = IndexOfClosestPointLeftOf(t);
// Differentiation
double offset = t - _points[closestLeftIndex];
int k = closestLeftIndex << 2;
interpolatedValue = _coefficients[k]
+ (offset*(_coefficients[k + 1]
+ (offset*(_coefficients[k + 2]
+ (offset*_coefficients[k + 3])))));
secondDerivative = (2*_coefficients[k + 2])
+ (6*offset*_coefficients[k + 3]);
return _coefficients[k + 1]
+ (2*offset*_coefficients[k + 2])
+ (3*offset*offset*_coefficients[k + 3]);
return new Tuple<double, double, double>(
_coefficients[k] + (offset*(_coefficients[k + 1] + (offset*(_coefficients[k + 2] + (offset*_coefficients[k + 3]))))),
_coefficients[k + 1] + (2*offset*_coefficients[k + 2]) + (3*offset*offset*_coefficients[k + 3]),
(2*_coefficients[k + 2]) + (6*offset*_coefficients[k + 3]));
}
/// <summary>

14
src/UnitTests/InterpolationTests/AkimaSplineTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2002-2011 Math.NET
// Copyright (c) 2002-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -61,10 +61,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative);
Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
}
}
@ -90,10 +88,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
// TODO: Verify the expected values (that they are really the expected ones)
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(t, out interpolatedValue, out secondDerivative);
Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
}
/// <summary>

41
src/UnitTests/InterpolationTests/CubicSplineTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2002-2011 Math.NET
// Copyright (c) 2002-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -31,9 +31,6 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests
{
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Interpolation;
using NUnit.Framework;
@ -65,10 +62,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative);
Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
}
}
@ -98,10 +93,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(t, out interpolatedValue, out secondDerivative);
Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
}
/// <summary>
@ -116,10 +109,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative);
Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
}
}
@ -149,10 +140,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(t, out interpolatedValue, out secondDerivative);
Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
}
/// <summary>
@ -167,10 +156,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative);
Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
}
}
@ -200,10 +187,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(t, out interpolatedValue, out secondDerivative);
Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
}
/// <summary>

17
src/UnitTests/InterpolationTests/LinearSplineTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2002-2011 Math.NET
// Copyright (c) 2002-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -31,9 +31,6 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests
{
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Interpolation;
using NUnit.Framework;
@ -65,10 +62,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative);
Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
}
}
@ -98,10 +93,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(t, out interpolatedValue, out secondDerivative);
Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
}
/// <summary>

12
src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

@ -65,10 +65,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative);
Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
}
}
@ -96,10 +94,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
double interpolatedValue;
double secondDerivative;
interpolation.Differentiate(t, out interpolatedValue, out secondDerivative);
Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
}
/// <summary>

Loading…
Cancel
Save