Browse Source

Interpolation: Differentiate2 instead of DifferentiateAll; definite integral; cleanup

pull/184/head
Christoph Ruegg 13 years ago
parent
commit
aebb93a04a
  1. 41
      src/Numerics/Interpolation/AkimaSplineInterpolation.cs
  2. 31
      src/Numerics/Interpolation/BarycentricInterpolation.cs
  3. 31
      src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
  4. 33
      src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs
  5. 33
      src/Numerics/Interpolation/CubicSplineInterpolation.cs
  6. 31
      src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs
  7. 31
      src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs
  8. 30
      src/Numerics/Interpolation/IInterpolation.cs
  9. 32
      src/Numerics/Interpolation/LinearSpline.cs
  10. 39
      src/Numerics/Interpolation/NevillePolynomialInterpolation.cs
  11. 70
      src/Numerics/Interpolation/SplineInterpolation.cs
  12. 16
      src/UnitTests/InterpolationTests/AkimaSplineTest.cs
  13. 12
      src/UnitTests/InterpolationTests/BulirschStoerRationalTest.cs
  14. 41
      src/UnitTests/InterpolationTests/CubicSplineTest.cs
  15. 14
      src/UnitTests/InterpolationTests/EquidistantPolynomialTest.cs
  16. 18
      src/UnitTests/InterpolationTests/FloaterHormannRationalTest.cs
  17. 8
      src/UnitTests/InterpolationTests/LinearInterpolationCase.cs
  18. 70
      src/UnitTests/InterpolationTests/LinearSplineTest.cs
  19. 28
      src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

41
src/Numerics/Interpolation/AkimaSplineInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -69,8 +69,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return true; } get { return true; }
@ -79,7 +77,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return true; } get { return true; }
@ -155,11 +152,11 @@ namespace MathNet.Numerics.Interpolation
derivatives[i] = derivatives[i] =
weights[i - 1].AlmostEqual(0.0) && weights[i + 1].AlmostEqual(0.0) weights[i - 1].AlmostEqual(0.0) && weights[i + 1].AlmostEqual(0.0)
? (((samplePoints[i + 1] - samplePoints[i])*differences[i - 1]) ? (((samplePoints[i + 1] - samplePoints[i])*differences[i - 1])
+ ((samplePoints[i] - samplePoints[i - 1])*differences[i])) + ((samplePoints[i] - samplePoints[i - 1])*differences[i]))
/(samplePoints[i + 1] - samplePoints[i - 1]) /(samplePoints[i + 1] - samplePoints[i - 1])
: ((weights[i + 1]*differences[i - 1]) : ((weights[i + 1]*differences[i - 1])
+ (weights[i - 1]*differences[i])) + (weights[i - 1]*differences[i]))
/(weights[i + 1] + weights[i - 1]); /(weights[i + 1] + weights[i - 1]);
} }
derivatives[0] = DifferentiateThreePoint(samplePoints, sampleValues, 0, 0, 1, 2); derivatives[0] = DifferentiateThreePoint(samplePoints, sampleValues, 0, 0, 1, 2);
@ -227,34 +224,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t) public double Differentiate(double t)
{ {
return _spline.Differentiate(t); return _spline.Differentiate(t);
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Differentiate twice at point t.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> public double Differentiate2(double t)
/// <seealso cref="Differentiate(double)"/>
public Tuple<double, double, double> DifferentiateAll(double t)
{ {
return _spline.DifferentiateAll(t); return _spline.Differentiate2(t);
} }
/// <summary> /// <summary>
/// Integrate up to point t. /// Indefinite integral at point t.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
public double Integrate(double t) public double Integrate(double t)
{ {
return _spline.Integrate(t); return _spline.Integrate(t);
} }
/// <summary>
/// Definite integral between points a and b.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
public double Integrate(double a, double b)
{
return _spline.Integrate(a, b);
}
} }
} }

31
src/Numerics/Interpolation/BarycentricInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -77,8 +77,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return false; } get { return false; }
@ -87,7 +85,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return false; } get { return false; }
@ -201,34 +198,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t) double IInterpolation.Differentiate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// Differentiate twice at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> double IInterpolation.Differentiate2(double t)
/// <seealso cref="IInterpolation.Differentiate(double)"/>
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Integrate up to point t. NOT SUPPORTED. /// Indefinite integral at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
double IInterpolation.Integrate(double t) double IInterpolation.Integrate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Definite integral between points a and b. NOT SUPPORTED.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
double IInterpolation.Integrate(double a, double b)
{
throw new NotSupportedException();
}
} }
} }

31
src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -73,8 +73,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return false; } get { return false; }
@ -83,7 +81,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return false; } get { return false; }
@ -187,34 +184,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t) double IInterpolation.Differentiate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// Differentiate twice at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> double IInterpolation.Differentiate2(double t)
/// <seealso cref="IInterpolation.Differentiate(double)"/>
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Integrate up to point t. NOT SUPPORTED. /// Indefinite integral at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
double IInterpolation.Integrate(double t) double IInterpolation.Integrate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Definite integral between points a and b. NOT SUPPORTED.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
double IInterpolation.Integrate(double a, double b)
{
throw new NotSupportedException();
}
} }
} }

33
src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -70,8 +70,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return true; } get { return true; }
@ -80,7 +78,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return true; } get { return true; }
@ -169,34 +166,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t) public double Differentiate(double t)
{ {
return _spline.Differentiate(t); return _spline.Differentiate(t);
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Differentiate twice at point t.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> public double Differentiate2(double t)
/// <seealso cref="Differentiate(double)"/>
public Tuple<double, double, double> DifferentiateAll(double t)
{ {
return _spline.DifferentiateAll(t); return _spline.Differentiate2(t);
} }
/// <summary> /// <summary>
/// Integrate up to point t. /// Indefinite integral at point t.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
public double Integrate(double t) public double Integrate(double t)
{ {
return _spline.Integrate(t); return _spline.Integrate(t);
} }
/// <summary>
/// Definite integral between points a and b.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
public double Integrate(double a, double b)
{
return _spline.Integrate(a, b);
}
} }
} }

33
src/Numerics/Interpolation/CubicSplineInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -91,8 +91,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return true; } get { return true; }
@ -101,7 +99,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return true; } get { return true; }
@ -339,34 +336,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t) public double Differentiate(double t)
{ {
return _spline.Differentiate(t); return _spline.Differentiate(t);
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Differentiate twice at point t.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> public double Differentiate2(double t)
/// <seealso cref="Differentiate(double)"/>
public Tuple<double, double, double> DifferentiateAll(double t)
{ {
return _spline.DifferentiateAll(t); return _spline.Differentiate2(t);
} }
/// <summary> /// <summary>
/// Integrate up to point t. /// Indefinite integral at point t.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
public double Integrate(double t) public double Integrate(double t)
{ {
return _spline.Integrate(t); return _spline.Integrate(t);
} }
/// <summary>
/// Definite integral between points a and b.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
public double Integrate(double a, double b)
{
return _spline.Integrate(a, b);
}
} }
} }

31
src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -80,8 +80,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return false; } get { return false; }
@ -90,7 +88,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return false; } get { return false; }
@ -181,34 +178,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t) double IInterpolation.Differentiate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// Differentiate twice at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> double IInterpolation.Differentiate2(double t)
/// <seealso cref="IInterpolation.Differentiate(double)"/>
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Integrate up to point t. NOT SUPPORTED. /// Indefinite integral at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
double IInterpolation.Integrate(double t) double IInterpolation.Integrate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Definite integral between points a and b. NOT SUPPORTED.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
double IInterpolation.Integrate(double a, double b)
{
throw new NotSupportedException();
}
} }
} }

31
src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -83,8 +83,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Differentiate(double)"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return false; } get { return false; }
@ -93,7 +91,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return false; } get { return false; }
@ -250,34 +247,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="IInterpolation.DifferentiateAll(double)"/>
double IInterpolation.Differentiate(double t) double IInterpolation.Differentiate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// Differentiate twice at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> double IInterpolation.Differentiate2(double t)
/// <seealso cref="IInterpolation.Differentiate(double)"/>
Tuple<double, double, double> IInterpolation.DifferentiateAll(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary> /// <summary>
/// Integrate up to point t. NOT SUPPORTED. /// Indefinite integral at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
double IInterpolation.Integrate(double t) double IInterpolation.Integrate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Definite integral between points a and b. NOT SUPPORTED.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
double IInterpolation.Integrate(double a, double b)
{
throw new NotSupportedException();
}
} }
} }

30
src/Numerics/Interpolation/IInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -28,8 +28,6 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
namespace MathNet.Numerics.Interpolation namespace MathNet.Numerics.Interpolation
{ {
/// <summary> /// <summary>
@ -40,14 +38,11 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool SupportsDifferentiation { get; } bool SupportsDifferentiation { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="Integrate"/>
bool SupportsIntegration { get; } bool SupportsIntegration { get; }
/// <summary> /// <summary>
@ -62,25 +57,26 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="SupportsDifferentiation"/>
/// <seealso cref="DifferentiateAll(double)"/>
double Differentiate(double t); double Differentiate(double t);
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Differentiate twice at point t.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="SupportsDifferentiation"/> double Differentiate2(double t);
/// <seealso cref="Differentiate(double)"/>
Tuple<double, double, double> DifferentiateAll(double t);
/// <summary> /// <summary>
/// Integrate up to point t. /// Indefinite integral at point t.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="SupportsIntegration"/>
double Integrate(double t); double Integrate(double t);
/// <summary>
/// Definite integral between points a and b.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
double Integrate(double a, double b);
} }
} }

32
src/Numerics/Interpolation/LinearSpline.cs

@ -44,6 +44,7 @@ namespace MathNet.Numerics.Interpolation
readonly double[] _x; readonly double[] _x;
readonly double[] _c0; readonly double[] _c0;
readonly double[] _c1; readonly double[] _c1;
readonly Lazy<double[]> _indefiniteIntegral;
/// <param name="x">Sample points (N+1), sorted ascending</param> /// <param name="x">Sample points (N+1), sorted ascending</param>
/// <param name="c0">Sample values (N or N+1) at the corresponding points; intercept, zero order coefficients</param> /// <param name="c0">Sample values (N or N+1) at the corresponding points; intercept, zero order coefficients</param>
@ -53,6 +54,7 @@ namespace MathNet.Numerics.Interpolation
_x = x; _x = x;
_c0 = c0; _c0 = c0;
_c1 = c1; _c1 = c1;
_indefiniteIntegral = new Lazy<double[]>(ComputeIndefiniteIntegral);
} }
/// <summary> /// <summary>
@ -132,27 +134,35 @@ namespace MathNet.Numerics.Interpolation
} }
/// <summary> /// <summary>
/// Integrate up to point t. /// Indefinite integral at point t.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
public double Integrate(double t) public double Integrate(double t)
{ {
int k = LeftBracketIndex(t); int k = LeftBracketIndex(t);
var x = (t - _x[k]); var x = (t - _x[k]);
return x*(_c0[k] + x*0.5*_c1[k]); return _indefiniteIntegral.Value[k] + x*(_c0[k] + x*_c1[k]/2);
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Definite integral between points a and b.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="a">Left bound of the integration interval [a,b].</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <param name="b">Right bound of the integration interval [a,b].</param>
public Tuple<double, double, double> DifferentiateAll(double t) public double Integrate(double a, double b)
{ {
int k = LeftBracketIndex(t); return Integrate(b) - Integrate(a);
var x = (t - _x[k]); }
return new Tuple<double, double, double>(_c0[k] + x*_c1[k], _c1[k], 0d);
double[] ComputeIndefiniteIntegral()
{
var integral = new double[_c1.Length];
for (int i = 0; i < integral.Length - 1; i++)
{
double w = _x[i + 1] - _x[i];
integral[i + 1] = integral[i] + w*(_c0[i] + w*_c1[i]/2);
}
return integral;
} }
/// <summary> /// <summary>

39
src/Numerics/Interpolation/NevillePolynomialInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -79,8 +79,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return true; } get { return true; }
@ -89,7 +87,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="IInterpolation.Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return false; } get { return false; }
@ -159,8 +156,6 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t) public double Differentiate(double t)
{ {
var x = new double[_values.Count]; var x = new double[_values.Count];
@ -183,13 +178,11 @@ namespace MathNet.Numerics.Interpolation
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Differentiate twice at point t.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> public double Differentiate2(double t)
/// <seealso cref="Differentiate(double)"/>
public Tuple<double, double, double> DifferentiateAll(double t)
{ {
var x = new double[_values.Count]; var x = new double[_values.Count];
var dx = new double[_values.Count]; var dx = new double[_values.Count];
@ -203,24 +196,32 @@ namespace MathNet.Numerics.Interpolation
double hp = t - _points[i + level]; double hp = t - _points[i + level];
double ho = _points[i] - t; double ho = _points[i] - t;
double den = _points[i] - _points[i + level]; double den = _points[i] - _points[i + level];
ddx[i] = ((hp * ddx[i]) + (ho * ddx[i + 1]) + (2 * dx[i]) - (2 * dx[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; 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; x[i] = ((hp*x[i]) + (ho*x[i + 1]))/den;
} }
} }
return new Tuple<double, double, double>(x[0], dx[0], ddx[0]); return ddx[0];
} }
/// <summary> /// <summary>
/// Integrate up to point t. NOT SUPPORTED. /// Indefinite integral at point t. NOT SUPPORTED.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
double IInterpolation.Integrate(double t) double IInterpolation.Integrate(double t)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Definite integral between points a and b. NOT SUPPORTED.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
double IInterpolation.Integrate(double a, double b)
{
throw new NotSupportedException();
}
} }
} }

70
src/Numerics/Interpolation/SplineInterpolation.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2010 Math.NET // Copyright (c) 2009-2013 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -77,8 +77,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
/// </summary> /// </summary>
/// <seealso cref="Differentiate(double)"/>
/// <seealso cref="DifferentiateAll(double)"/>
bool IInterpolation.SupportsDifferentiation bool IInterpolation.SupportsDifferentiation
{ {
get { return true; } get { return true; }
@ -87,7 +85,6 @@ namespace MathNet.Numerics.Interpolation
/// <summary> /// <summary>
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature). /// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
/// </summary> /// </summary>
/// <seealso cref="Integrate"/>
bool IInterpolation.SupportsIntegration bool IInterpolation.SupportsIntegration
{ {
get { return true; } get { return true; }
@ -136,16 +133,16 @@ namespace MathNet.Numerics.Interpolation
/// <returns>Interpolated value x(t).</returns> /// <returns>Interpolated value x(t).</returns>
public double Interpolate(double t) public double Interpolate(double t)
{ {
int closestLeftIndex = IndexOfClosestPointLeftOf(t); int closestLeftIndex = LeftBracketIndex(t);
// Interpolation // Interpolation
double offset = t - _points[closestLeftIndex]; double offset = t - _points[closestLeftIndex];
int k = closestLeftIndex << 2; int k = closestLeftIndex << 2;
return _coefficients[k] return _coefficients[k]
+ (offset*(_coefficients[k + 1] + (offset*(_coefficients[k + 1]
+ (offset*(_coefficients[k + 2] + (offset*(_coefficients[k + 2]
+ (offset*_coefficients[k + 3]))))); + (offset*_coefficients[k + 3])))));
} }
/// <summary> /// <summary>
@ -153,49 +150,38 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated first derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/>
/// <seealso cref="DifferentiateAll(double)"/>
public double Differentiate(double t) public double Differentiate(double t)
{ {
int closestLeftIndex = IndexOfClosestPointLeftOf(t); int closestLeftIndex = LeftBracketIndex(t);
// Differentiation
double offset = t - _points[closestLeftIndex]; double offset = t - _points[closestLeftIndex];
int k = closestLeftIndex << 2; int k = closestLeftIndex << 2;
return _coefficients[k + 1] return _coefficients[k + 1]
+ (2*offset*_coefficients[k + 2]) + (2*offset*_coefficients[k + 2])
+ (3*offset*offset*_coefficients[k + 3]); + (3*offset*offset*_coefficients[k + 3]);
} }
/// <summary> /// <summary>
/// Interpolate, differentiate and 2nd differentiate at point t. /// Differentiate twice at point t.
/// </summary> /// </summary>
/// <param name="t">Point t to interpolate at.</param> /// <param name="t">Point t to interpolate at.</param>
/// <returns>Interpolated first derivative at point t.</returns> /// <returns>Interpolated second derivative at point t.</returns>
/// <seealso cref="IInterpolation.SupportsDifferentiation"/> public double Differentiate2(double t)
/// <seealso cref="Differentiate(double)"/>
public Tuple<double, double, double> DifferentiateAll(double t)
{ {
int closestLeftIndex = IndexOfClosestPointLeftOf(t); int closestLeftIndex = LeftBracketIndex(t);
double offset = t - _points[closestLeftIndex]; double offset = t - _points[closestLeftIndex];
int k = closestLeftIndex << 2; int k = closestLeftIndex << 2;
return new Tuple<double, double, double>( return (2*_coefficients[k + 2]) + (6*offset*_coefficients[k + 3]);
_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> /// <summary>
/// Integrate up to point t. /// Indefinite integral at point t.
/// </summary> /// </summary>
/// <param name="t">Right bound of the integration interval [a,t].</param> /// <param name="t">Point t to integrate at.</param>
/// <returns>Interpolated definite integral over the interval [a,t].</returns>
/// <seealso cref="IInterpolation.SupportsIntegration"/>
public double Integrate(double t) public double Integrate(double t)
{ {
int closestLeftIndex = IndexOfClosestPointLeftOf(t); int closestLeftIndex = LeftBracketIndex(t);
// Integration // Integration
double result = 0; double result = 0;
@ -203,18 +189,28 @@ namespace MathNet.Numerics.Interpolation
{ {
double w = _points[i + 1] - _points[i]; double w = _points[i + 1] - _points[i];
result += w*(_coefficients[j] result += w*(_coefficients[j]
+ ((w*_coefficients[j + 1]*0.5) + ((w*_coefficients[j + 1]*0.5)
+ (w*((_coefficients[j + 2]/3) + (w*((_coefficients[j + 2]/3)
+ (w*_coefficients[j + 3]*0.25))))); + (w*_coefficients[j + 3]*0.25)))));
} }
double offset = t - _points[closestLeftIndex]; double offset = t - _points[closestLeftIndex];
int k = closestLeftIndex << 2; int k = closestLeftIndex << 2;
return result + (offset*(_coefficients[k] return result + (offset*(_coefficients[k]
+ (offset*_coefficients[k + 1]*0.5) + (offset*_coefficients[k + 1]*0.5)
+ (offset*_coefficients[k + 2]/3) + (offset*_coefficients[k + 2]/3)
+ (offset*_coefficients[k + 3]*0.25))); + (offset*_coefficients[k + 3]*0.25)));
}
/// <summary>
/// Definite integral between points a and b.
/// </summary>
/// <param name="a">Left bound of the integration interval [a,b].</param>
/// <param name="b">Right bound of the integration interval [a,b].</param>
public double Integrate(double a, double b)
{
return Integrate(b) - Integrate(a);
} }
/// <summary> /// <summary>
@ -222,7 +218,7 @@ namespace MathNet.Numerics.Interpolation
/// </summary> /// </summary>
/// <param name="t">The value to look for.</param> /// <param name="t">The value to look for.</param>
/// <returns>The sample point index.</returns> /// <returns>The sample point index.</returns>
int IndexOfClosestPointLeftOf(double t) int LeftBracketIndex(double t)
{ {
// Binary search in the [ t[0], ..., t[n-2] ] (t[n-1] is not included) // Binary search in the [ t[0], ..., t[n-2] ] (t[n-1] is not included)
int low = 0; int low = 0;

16
src/UnitTests/InterpolationTests/AkimaSplineTest.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.Interpolation;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using Interpolation;
using NUnit.Framework;
/// <summary> /// <summary>
/// AkimaSpline test case. /// AkimaSpline test case.
/// </summary> /// </summary>
@ -42,12 +42,12 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary> /// <summary>
/// Sample points. /// Sample points.
/// </summary> /// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 }; readonly double[] _t = { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary> /// <summary>
/// Sample values. /// Sample values.
/// </summary> /// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 }; readonly double[] _x = { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points. /// Verifies that the interpolation matches the given value at all the provided sample points.
@ -60,9 +60,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < _x.Length; i++) for (int i = 0; i < _x.Length; i++)
{ {
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
} }
} }
@ -87,9 +84,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
// TODO: Verify the expected values (that they are really the expected ones) // TODO: Verify the expected values (that they are really the expected ones)
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
} }
/// <summary> /// <summary>

12
src/UnitTests/InterpolationTests/BulirschStoerRationalTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // 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 // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.Interpolation;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using Interpolation;
using NUnit.Framework;
/// <summary> /// <summary>
/// BulirschStoerRational test case. /// BulirschStoerRational test case.
/// </summary> /// </summary>
@ -42,12 +42,12 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary> /// <summary>
/// Sample points. /// Sample points.
/// </summary> /// </summary>
private readonly double[] _t = new[] { 0d, 1, 3, 4, 5 }; readonly double[] _t = { 0d, 1, 3, 4, 5 };
/// <summary> /// <summary>
/// Sample values. /// Sample values.
/// </summary> /// </summary>
private readonly double[] _x = new[] { 0d, 3, 1000, -1000, 3 }; readonly double[] _x = { 0d, 3, 1000, -1000, 3 };
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points. /// Verifies that the interpolation matches the given value at all the provided sample points.

41
src/UnitTests/InterpolationTests/CubicSplineTest.cs

@ -28,12 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.Interpolation;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using System;
using Interpolation;
using NUnit.Framework;
/// <summary> /// <summary>
/// CubicSpline Test case. /// CubicSpline Test case.
/// </summary> /// </summary>
@ -43,12 +42,12 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary> /// <summary>
/// Sample points. /// Sample points.
/// </summary> /// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 }; readonly double[] _t = { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary> /// <summary>
/// Sample values. /// Sample values.
/// </summary> /// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 }; readonly double[] _x = { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points. /// Verifies that the interpolation matches the given value at all the provided sample points.
@ -61,9 +60,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < _x.Length; i++) for (int i = 0; i < _x.Length; i++)
{ {
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
} }
} }
@ -92,9 +88,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); IInterpolation interpolation = new CubicSplineInterpolation(_t, _x);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
} }
/// <summary> /// <summary>
@ -108,9 +101,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < _x.Length; i++) for (int i = 0; i < _x.Length; i++)
{ {
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
} }
} }
@ -139,9 +129,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0); IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
} }
/// <summary> /// <summary>
@ -155,9 +142,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < _x.Length; i++) for (int i = 0; i < _x.Length; i++)
{ {
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
} }
} }
@ -186,9 +170,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
} }
/// <summary> /// <summary>
@ -208,17 +189,5 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
Assert.AreEqual(ytest[i], interpolation.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i); Assert.AreEqual(ytest[i], interpolation.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i);
} }
} }
/// <summary>
/// Verifies that sample points are required to be sorted in strictly monotonically ascending order.
/// </summary>
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Constructor_SamplePointsNotStrictlyAscending_Throws()
{
var x = new[] { -1.0, 0.0, 1.5, 1.5, 2.5, 4.0 };
var y = new[] { 1.0, 0.3, -0.7, -0.6, -0.1, 0.4 };
var interpolation = new CubicSplineInterpolation(x, y);
}
} }
} }

14
src/UnitTests/InterpolationTests/EquidistantPolynomialTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // 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 // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.Interpolation;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using Interpolation;
using NUnit.Framework;
/// <summary> /// <summary>
/// EquidistantPolynomial Test case. /// EquidistantPolynomial Test case.
/// </summary> /// </summary>
@ -42,17 +42,17 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary> /// <summary>
/// Left bound; /// Left bound;
/// </summary> /// </summary>
private const double Tmin = 0.0; const double Tmin = 0.0;
/// <summary> /// <summary>
/// Right bound. /// Right bound.
/// </summary> /// </summary>
private const double Tmax = 4.0; const double Tmax = 4.0;
/// <summary> /// <summary>
/// Sample values. /// Sample values.
/// </summary> /// </summary>
private readonly double[] _x = new[] { 0.0, 3.0, 2.5, 1.0, 3.0 }; readonly double[] _x = { 0.0, 3.0, 2.5, 1.0, 3.0 };
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points. /// Verifies that the interpolation matches the given value at all the provided sample points.

18
src/UnitTests/InterpolationTests/FloaterHormannRationalTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // 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 // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.Interpolation;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using Interpolation;
using NUnit.Framework;
/// <summary> /// <summary>
/// FloaterHormannRational test case. /// FloaterHormannRational test case.
/// </summary> /// </summary>
@ -42,12 +42,12 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary> /// <summary>
/// Sample points. /// Sample points.
/// </summary> /// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 }; readonly double[] _t = { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary> /// <summary>
/// Sample values. /// Sample values.
/// </summary> /// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 }; readonly double[] _x = { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided polynomial sample points. /// Verifies that the interpolation matches the given value at all the provided polynomial sample points.
@ -99,12 +99,12 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
var t = new double[40]; var t = new double[40];
var x = new double[40]; var x = new double[40];
const double Step = 10.0 / 39.0; const double Step = 10.0/39.0;
for (int i = 0; i < t.Length; i++) for (int i = 0; i < t.Length; i++)
{ {
double tt = -5 + (i * Step); double tt = -5 + (i*Step);
t[i] = tt; t[i] = tt;
x[i] = 1.0 / (1.0 + (tt * tt)); x[i] = 1.0/(1.0 + (tt*tt));
} }
IInterpolation interpolation = new FloaterHormannRationalInterpolation(t, x); IInterpolation interpolation = new FloaterHormannRationalInterpolation(t, x);

8
src/UnitTests/InterpolationTests/LinearInterpolationCase.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // 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 // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -60,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < x.Length; i++) for (int i = 0; i < x.Length; i++)
{ {
x[i] = i + sampleOffset; x[i] = i + sampleOffset;
y[i] = (x[i] * slope) + intercept; y[i] = (x[i]*slope) + intercept;
} }
// build linear test vectors randomly between the sample points // build linear test vectors randomly between the sample points
@ -71,14 +71,14 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
// y = const // y = const
xtest[0] = sampleOffset - uniform.Sample(); xtest[0] = sampleOffset - uniform.Sample();
xtest[1] = sampleOffset + uniform.Sample(); xtest[1] = sampleOffset + uniform.Sample();
ytest[0] = ytest[1] = (sampleOffset * slope) + intercept; ytest[0] = ytest[1] = (sampleOffset*slope) + intercept;
} }
else else
{ {
for (int i = 0; i < xtest.Length; i++) for (int i = 0; i < xtest.Length; i++)
{ {
xtest[i] = (i - 1) + sampleOffset + uniform.Sample(); xtest[i] = (i - 1) + sampleOffset + uniform.Sample();
ytest[i] = (xtest[i] * slope) + intercept; ytest[i] = (xtest[i]*slope) + intercept;
} }
} }
} }

70
src/UnitTests/InterpolationTests/LinearSplineTest.cs

@ -33,21 +33,46 @@ using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
/// <summary>
/// LinearSpline test case
/// </summary>
[TestFixture, Category("Interpolation")] [TestFixture, Category("Interpolation")]
public class LinearSplineTest public class LinearSplineTest
{ {
/// <summary>
/// Sample points.
/// </summary>
readonly double[] _t = { -2.0, -1.0, 0.0, 1.0, 2.0 }; 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 };
/// <summary> [Test]
/// Sample values. public void FirstDerivative()
/// </summary> {
readonly double[] _x = { 1.0, 2.0, -1.0, 0.0, 1.0 }; IInterpolation ip = LinearSpline.Interpolate(_t, _y);
Assert.That(ip.Differentiate(-3.0), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(-2.0), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(-1.5), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(-1.0), Is.EqualTo(-3.0));
Assert.That(ip.Differentiate(-0.5), Is.EqualTo(-3.0));
Assert.That(ip.Differentiate(0.0), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(0.5), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(1.0), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(2.0), Is.EqualTo(1.0));
Assert.That(ip.Differentiate(3.0), Is.EqualTo(1.0));
}
[Test]
public void DefiniteIntegral()
{
IInterpolation ip = LinearSpline.Interpolate(_t, _y);
Assert.That(ip.Integrate(-4.0, -3.0), Is.EqualTo(-0.5));
Assert.That(ip.Integrate(-3.0, -2.0), Is.EqualTo(0.5));
Assert.That(ip.Integrate(-2.0, -1.0), Is.EqualTo(1.5));
Assert.That(ip.Integrate(-1.0, 0.0), Is.EqualTo(0.5));
Assert.That(ip.Integrate(0.0, 1.0), Is.EqualTo(-0.5));
Assert.That(ip.Integrate(1.0, 2.0), Is.EqualTo(0.5));
Assert.That(ip.Integrate(2.0, 3.0), Is.EqualTo(1.5));
Assert.That(ip.Integrate(3.0, 4.0), Is.EqualTo(2.5));
Assert.That(ip.Integrate(0.0, 4.0), Is.EqualTo(4.0));
Assert.That(ip.Integrate(-3.0, -1.0), Is.EqualTo(2.0));
Assert.That(ip.Integrate(-3.0, 4.0), Is.EqualTo(6.5));
Assert.That(ip.Integrate(0.5, 1.5), Is.EqualTo(0.0));
Assert.That(ip.Integrate(-2.5, -1.0), Is.EqualTo(1.875));
}
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points. /// Verifies that the interpolation matches the given value at all the provided sample points.
@ -55,14 +80,10 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[Test] [Test]
public void FitsAtSamplePoints() public void FitsAtSamplePoints()
{ {
IInterpolation interpolation = LinearSpline.Interpolate(_t, _x); IInterpolation ip = LinearSpline.Interpolate(_t, _y);
for (int i = 0; i < _y.Length; i++)
for (int i = 0; i < _x.Length; i++)
{ {
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); Assert.AreEqual(_y[i], ip.Interpolate(_t[i]), "A Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
} }
} }
@ -86,14 +107,10 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[TestCase(1.2, .2, 1e-15)] [TestCase(1.2, .2, 1e-15)]
[TestCase(10.0, 9.0, 1e-15)] [TestCase(10.0, 9.0, 1e-15)]
[TestCase(-10.0, -7.0, 1e-15)] [TestCase(-10.0, -7.0, 1e-15)]
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) public void FitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
{ {
IInterpolation interpolation = LinearSpline.Interpolate(_t, _x); IInterpolation ip = LinearSpline.Interpolate(_t, _y);
Assert.AreEqual(x, ip.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
} }
/// <summary> /// <summary>
@ -107,10 +124,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
double[] x, y, xtest, ytest; double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples); LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);
IInterpolation interpolation = LinearSpline.Interpolate(x, y);
IInterpolation ip = LinearSpline.Interpolate(x, y);
for (int i = 0; i < xtest.Length; i++) for (int i = 0; i < xtest.Length; i++)
{ {
Assert.AreEqual(ytest[i], interpolation.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i); Assert.AreEqual(ytest[i], ip.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i);
} }
} }
} }

28
src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // 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 // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -28,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using MathNet.Numerics.Interpolation;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Interpolation;
using NUnit.Framework;
/// <summary> /// <summary>
/// NevillePolynomial test case. /// NevillePolynomial test case.
/// </summary> /// </summary>
@ -46,12 +46,12 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary> /// <summary>
/// Sample points. /// Sample points.
/// </summary> /// </summary>
private readonly double[] _t = new[] { 0.0, 1.0, 3.0, 4.0 }; readonly double[] _t = { 0.0, 1.0, 3.0, 4.0 };
/// <summary> /// <summary>
/// Sample values. /// Sample values.
/// </summary> /// </summary>
private readonly double[] _x = new[] { 0.0, 3.0, 1.0, 3.0 }; readonly double[] _x = { 0.0, 3.0, 1.0, 3.0 };
/// <summary> /// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points. /// Verifies that the interpolation matches the given value at all the provided sample points.
@ -64,9 +64,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < _x.Length; i++) for (int i = 0; i < _x.Length; i++)
{ {
Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
var actual = interpolation.DifferentiateAll(_t[i]);
Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i);
} }
} }
@ -93,9 +90,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
IInterpolation interpolation = new NevillePolynomialInterpolation(_t, _x); IInterpolation interpolation = new NevillePolynomialInterpolation(_t, _x);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
var actual = interpolation.DifferentiateAll(t);
Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t);
} }
/// <summary> /// <summary>
@ -120,7 +114,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// Verifies that all sample points must be unique. /// Verifies that all sample points must be unique.
/// </summary> /// </summary>
[Test] [Test]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof (ArgumentException))]
public void Constructor_SamplePointsNotUnique_Throws() public void Constructor_SamplePointsNotUnique_Throws()
{ {
var x = new[] { -1.0, 0.0, 1.5, 1.5, 2.5, 4.0 }; var x = new[] { -1.0, 0.0, 1.5, 1.5, 2.5, 4.0 };

Loading…
Cancel
Save