From 9af57cf3d63ab4b3db117cb406c54004626f9daa Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 28 Jul 2013 15:14:29 +0200 Subject: [PATCH] Interpolation: computing interpolation 1st/2nd derivative at once should use tuple type instead of out parameters --- src/Numerics/Interpolate.cs | 6 +-- .../Interpolation/AkimaSplineInterpolation.cs | 15 +++---- .../Interpolation/BarycentricInterpolation.cs | 17 +++----- .../BulirschStoerRationalInterpolation.cs | 17 +++----- .../CubicHermiteSplineInterpolation.cs | 15 +++---- .../Interpolation/CubicSplineInterpolation.cs | 15 +++---- .../EquidistantPolynomialInterpolation.cs | 17 +++----- .../FloaterHormannRationalInterpolation.cs | 17 +++----- src/Numerics/Interpolation/IInterpolation.cs | 15 +++---- .../LinearSplineInterpolation.cs | 15 +++---- .../NevillePolynomialInterpolation.cs | 31 ++++++-------- .../Interpolation/SplineInterpolation.cs | 30 ++++---------- .../InterpolationTests/AkimaSplineTest.cs | 14 +++---- .../InterpolationTests/CubicSplineTest.cs | 41 ++++++------------- .../InterpolationTests/LinearSplineTest.cs | 17 +++----- .../NevillePolynomialTest.cs | 12 ++---- 16 files changed, 100 insertions(+), 194 deletions(-) diff --git a/src/Numerics/Interpolate.cs b/src/Numerics/Interpolate.cs index 8398fd3d..c558526a 100644 --- a/src/Numerics/Interpolate.cs +++ b/src/Numerics/Interpolate.cs @@ -69,7 +69,7 @@ namespace MathNet.Numerics IList points, IList values) { - LinearSplineInterpolation method = new LinearSplineInterpolation(); + var method = new LinearSplineInterpolation(); method.Initialize(points, values); return method; } @@ -88,7 +88,7 @@ namespace MathNet.Numerics IList points, IList values) { - FloaterHormannRationalInterpolation method = new FloaterHormannRationalInterpolation(); + var method = new FloaterHormannRationalInterpolation(); method.Initialize(points, values); return method; } @@ -107,7 +107,7 @@ namespace MathNet.Numerics IList points, IList values) { - BulirschStoerRationalInterpolation method = new BulirschStoerRationalInterpolation(); + var method = new BulirschStoerRationalInterpolation(); method.Initialize(points, values); return method; } diff --git a/src/Numerics/Interpolation/AkimaSplineInterpolation.cs b/src/Numerics/Interpolation/AkimaSplineInterpolation.cs index 3786d9de..de5180cf 100644 --- a/src/Numerics/Interpolation/AkimaSplineInterpolation.cs +++ b/src/Numerics/Interpolation/AkimaSplineInterpolation.cs @@ -72,7 +72,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return true; } @@ -249,27 +249,22 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// public double Differentiate(double t) { return _spline.Differentiate(t); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - public double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + public Tuple DifferentiateAll(double t) { - return _spline.Differentiate(t, out interpolatedValue, out secondDerivative); + return _spline.DifferentiateAll(t); } /// diff --git a/src/Numerics/Interpolation/BarycentricInterpolation.cs b/src/Numerics/Interpolation/BarycentricInterpolation.cs index 17ec2022..3ba724b6 100644 --- a/src/Numerics/Interpolation/BarycentricInterpolation.cs +++ b/src/Numerics/Interpolation/BarycentricInterpolation.cs @@ -81,7 +81,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return false; } @@ -203,36 +203,31 @@ namespace MathNet.Numerics.Interpolation } /// - /// Differentiate at point t. + /// Differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// double IInterpolation.Differentiate(double t) { throw new NotSupportedException(); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - double IInterpolation.Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + Tuple IInterpolation.DifferentiateAll(double t) { throw new NotSupportedException(); } /// - /// Integrate up to point t. + /// Integrate up to point t. NOT SUPPORTED. /// /// Right bound of the integration interval [a,t]. /// Interpolated definite integral over the interval [a,t]. diff --git a/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs b/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs index 832cef0b..433203e8 100644 --- a/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs +++ b/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs @@ -76,7 +76,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return false; } @@ -187,36 +187,31 @@ namespace MathNet.Numerics.Interpolation } /// - /// Differentiate at point t. + /// Differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// double IInterpolation.Differentiate(double t) { throw new NotSupportedException(); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - double IInterpolation.Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + Tuple IInterpolation.DifferentiateAll(double t) { throw new NotSupportedException(); } /// - /// Integrate up to point t. + /// Integrate up to point t. NOT SUPPORTED. /// /// Right bound of the integration interval [a,t]. /// Interpolated definite integral over the interval [a,t]. diff --git a/src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs b/src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs index 296158e4..23649bd6 100644 --- a/src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs +++ b/src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs @@ -74,7 +74,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return true; } @@ -183,27 +183,22 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// public double Differentiate(double t) { return _spline.Differentiate(t); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - public double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + public Tuple DifferentiateAll(double t) { - return _spline.Differentiate(t, out interpolatedValue, out secondDerivative); + return _spline.DifferentiateAll(t); } /// diff --git a/src/Numerics/Interpolation/CubicSplineInterpolation.cs b/src/Numerics/Interpolation/CubicSplineInterpolation.cs index 987cf4a6..4efb1419 100644 --- a/src/Numerics/Interpolation/CubicSplineInterpolation.cs +++ b/src/Numerics/Interpolation/CubicSplineInterpolation.cs @@ -103,7 +103,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return true; } @@ -383,27 +383,22 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// public double Differentiate(double t) { return _spline.Differentiate(t); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - public double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + public Tuple DifferentiateAll(double t) { - return _spline.Differentiate(t, out interpolatedValue, out secondDerivative); + return _spline.DifferentiateAll(t); } /// diff --git a/src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs b/src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs index 0a3bceb0..3b8d5742 100644 --- a/src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs +++ b/src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs @@ -86,7 +86,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return false; } @@ -189,36 +189,31 @@ namespace MathNet.Numerics.Interpolation } /// - /// Differentiate at point t. + /// Differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// double IInterpolation.Differentiate(double t) { throw new NotSupportedException(); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - double IInterpolation.Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + Tuple IInterpolation.DifferentiateAll(double t) { throw new NotSupportedException(); } /// - /// Integrate up to point t. + /// Integrate up to point t. NOT SUPPORTED. /// /// Right bound of the integration interval [a,t]. /// Interpolated definite integral over the interval [a,t]. diff --git a/src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs b/src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs index c8350ded..90ea01c3 100644 --- a/src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs +++ b/src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs @@ -89,7 +89,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return false; } @@ -266,36 +266,31 @@ namespace MathNet.Numerics.Interpolation } /// - /// Differentiate at point t. + /// Differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// double IInterpolation.Differentiate(double t) { throw new NotSupportedException(); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. NOT SUPPORTED. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - double IInterpolation.Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + Tuple IInterpolation.DifferentiateAll(double t) { throw new NotSupportedException(); } /// - /// Integrate up to point t. + /// Integrate up to point t. NOT SUPPORTED. /// /// Right bound of the integration interval [a,t]. /// Interpolated definite integral over the interval [a,t]. diff --git a/src/Numerics/Interpolation/IInterpolation.cs b/src/Numerics/Interpolation/IInterpolation.cs index 2acd9589..d36fb344 100644 --- a/src/Numerics/Interpolation/IInterpolation.cs +++ b/src/Numerics/Interpolation/IInterpolation.cs @@ -28,6 +28,8 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; + namespace MathNet.Numerics.Interpolation { /// @@ -39,7 +41,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool SupportsDifferentiation { get; } /// @@ -61,22 +63,17 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// double Differentiate(double t); /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative); + Tuple DifferentiateAll(double t); /// /// Integrate up to point t. diff --git a/src/Numerics/Interpolation/LinearSplineInterpolation.cs b/src/Numerics/Interpolation/LinearSplineInterpolation.cs index adf0f08d..9d122360 100644 --- a/src/Numerics/Interpolation/LinearSplineInterpolation.cs +++ b/src/Numerics/Interpolation/LinearSplineInterpolation.cs @@ -72,7 +72,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return true; } @@ -167,27 +167,22 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// public double Differentiate(double t) { return _spline.Differentiate(t); } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - public double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + public Tuple DifferentiateAll(double t) { - return _spline.Differentiate(t, out interpolatedValue, out secondDerivative); + return _spline.DifferentiateAll(t); } /// diff --git a/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs b/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs index 315ee81b..af8fe7a7 100644 --- a/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs +++ b/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs @@ -82,7 +82,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return true; } @@ -164,7 +164,7 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// public double Differentiate(double t) { double[] x = new double[_values.Count]; @@ -187,22 +187,17 @@ namespace MathNet.Numerics.Interpolation } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - public double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + public Tuple 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(x[0], dx[0], ddx[0]); } /// - /// Integrate up to point t. + /// Integrate up to point t. NOT SUPPORTED. /// /// Right bound of the integration interval [a,t]. /// Interpolated definite integral over the interval [a,t]. diff --git a/src/Numerics/Interpolation/SplineInterpolation.cs b/src/Numerics/Interpolation/SplineInterpolation.cs index ff0d694d..d678c06a 100644 --- a/src/Numerics/Interpolation/SplineInterpolation.cs +++ b/src/Numerics/Interpolation/SplineInterpolation.cs @@ -80,7 +80,7 @@ namespace MathNet.Numerics.Interpolation /// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative). /// /// - /// + /// bool IInterpolation.SupportsDifferentiation { get { return true; } @@ -158,7 +158,7 @@ namespace MathNet.Numerics.Interpolation /// Point t to interpolate at. /// Interpolated first derivative at point t. /// - /// + /// public double Differentiate(double t) { int closestLeftIndex = IndexOfClosestPointLeftOf(t); @@ -173,36 +173,22 @@ namespace MathNet.Numerics.Interpolation } /// - /// Differentiate at point t. + /// Interpolate, differentiate and 2nd differentiate at point t. /// /// Point t to interpolate at. - /// Interpolated value x(t) - /// Interpolated second derivative at point t. /// Interpolated first derivative at point t. /// /// - public double Differentiate( - double t, - out double interpolatedValue, - out double secondDerivative) + public Tuple 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( + _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])); } /// diff --git a/src/UnitTests/InterpolationTests/AkimaSplineTest.cs b/src/UnitTests/InterpolationTests/AkimaSplineTest.cs index e70d7c03..5f3453e1 100644 --- a/src/UnitTests/InterpolationTests/AkimaSplineTest.cs +++ b/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); } /// diff --git a/src/UnitTests/InterpolationTests/CubicSplineTest.cs b/src/UnitTests/InterpolationTests/CubicSplineTest.cs index fcab0bdb..2c75dcb3 100644 --- a/src/UnitTests/InterpolationTests/CubicSplineTest.cs +++ b/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); } /// @@ -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); } /// @@ -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); } /// diff --git a/src/UnitTests/InterpolationTests/LinearSplineTest.cs b/src/UnitTests/InterpolationTests/LinearSplineTest.cs index 62d119bb..d6552f13 100644 --- a/src/UnitTests/InterpolationTests/LinearSplineTest.cs +++ b/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); } /// diff --git a/src/UnitTests/InterpolationTests/NevillePolynomialTest.cs b/src/UnitTests/InterpolationTests/NevillePolynomialTest.cs index c328dc2d..314534a8 100644 --- a/src/UnitTests/InterpolationTests/NevillePolynomialTest.cs +++ b/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); } ///