From cedff536f7b7c79f74ac0afd97fd73e5a55460b9 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Wed, 22 May 2013 23:00:20 +0200 Subject: [PATCH] RootFinding: cubic tests now use EvaluatePolynomial --- src/UnitTests/RootFindingTests/BrentTest.cs | 8 ++++---- src/UnitTests/RootFindingTests/NewtonRaphsonTest.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/UnitTests/RootFindingTests/BrentTest.cs b/src/UnitTests/RootFindingTests/BrentTest.cs index 94067a1a..2b4176db 100644 --- a/src/UnitTests/RootFindingTests/BrentTest.cs +++ b/src/UnitTests/RootFindingTests/BrentTest.cs @@ -69,12 +69,12 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests [Test] public void Cubic() { - // with complex roots (looking for the real root only) - Func f1 = x => 3 * x * x * x + 4 * x * x + 5 * x + 6; + // with complex roots (looking for the real root only): 3x^3 + 4x^2 + 5x + 6 + Func f1 = x => Evaluate.Polynomial(x, 6, 5, 4, 3); Assert.AreEqual(-1.265328088928, Brent.FindRoot(f1, -2, -1, 1e-8, 100), 1e-6); - // real roots only - Func f2 = x => 2 * x * x * x + 4 * x * x - 50 * x + 6; + // real roots only: 2x^3 + 4x^2 - 50x + 6 + Func f2 = x => Evaluate.Polynomial(x, 6, -50, 4, 2); Assert.AreEqual(-6.1466562197069, Brent.FindRoot(f2, -6.5, -5.5, 1e-8, 100), 1e-6); Assert.AreEqual(0.12124737195841, Brent.FindRoot(f2, -0.5, 0.5, 1e-8, 100), 1e-6); Assert.AreEqual(4.0254088477485, Brent.FindRoot(f2, 3.5, 4.5, 1e-8, 100), 1e-6); diff --git a/src/UnitTests/RootFindingTests/NewtonRaphsonTest.cs b/src/UnitTests/RootFindingTests/NewtonRaphsonTest.cs index 9fa69da7..c01fd3da 100644 --- a/src/UnitTests/RootFindingTests/NewtonRaphsonTest.cs +++ b/src/UnitTests/RootFindingTests/NewtonRaphsonTest.cs @@ -103,15 +103,15 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests [Test] public void Cubic() { - // with complex roots (looking for the real root only) - Func f1 = x => 3*x*x*x + 4*x*x + 5*x + 6; - Func df1 = x => 9*x*x + 8*x + 5; + // with complex roots (looking for the real root only): 3x^3 + 4x^2 + 5x + 6, derivative 9x^2 + 8x + 5 + Func f1 = x => Evaluate.Polynomial(x, 6, 5, 4, 3); + Func df1 = x => Evaluate.Polynomial(x, 5, 8, 9); Assert.AreEqual(-1.265328088928, HybridNewtonRaphson.FindRoot(f1, df1, -2, -1, 1e-10, 100, 20), 1e-6); Assert.AreEqual(-1.265328088928, HybridNewtonRaphson.FindRoot(f1, df1, -5, 5, 1e-10, 100, 20), 1e-6); - // real roots only - Func f2 = x => 2*x*x*x + 4*x*x - 50*x + 6; - Func df2 = x => 6*x*x + 8*x - 50; + // real roots only: 2x^3 + 4x^2 - 50x + 6, derivative 6x^2 + 8x - 50 + Func f2 = x => Evaluate.Polynomial(x, 6, -50, 4, 2); + Func df2 = x => Evaluate.Polynomial(x, -50, 8, 6); Assert.AreEqual(-6.1466562197069, HybridNewtonRaphson.FindRoot(f2, df2, -8, -5, 1e-10, 100, 20), 1e-6); Assert.AreEqual(0.12124737195841, HybridNewtonRaphson.FindRoot(f2, df2, -1, 1, 1e-10, 100, 20), 1e-6); Assert.AreEqual(4.0254088477485, HybridNewtonRaphson.FindRoot(f2, df2, 3, 5, 1e-10, 100, 20), 1e-6);