From 4f6236a2d4347b4c822c19e2f01e76ce20332caf Mon Sep 17 00:00:00 2001 From: Aappo Pulkkinen Date: Wed, 3 Jan 2018 16:38:39 +0200 Subject: [PATCH] Added unit test demonstrating how Broyden method will fail if initial guess is close to coordinate axis. --- src/UnitTests/RootFindingTests/BroydenTest.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/UnitTests/RootFindingTests/BroydenTest.cs b/src/UnitTests/RootFindingTests/BroydenTest.cs index 729298e1..2da168fa 100644 --- a/src/UnitTests/RootFindingTests/BroydenTest.cs +++ b/src/UnitTests/RootFindingTests/BroydenTest.cs @@ -2643,5 +2643,25 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests Assert.AreEqual(0, fa1(r)[12], 1e-10); Assert.AreEqual(0, fa1(r)[13], 1e-11); } + + /// + /// Demonstrate how Broyden method fails because Jacobian step size approaches zero without limits + /// when the initial value approaches coordinate axis. + /// + [Test] + public void NumericalAccuracyProblemsWithBroydenMethod() + { + Func f = xa => { + var x1 = xa[0]; + var x2 = xa[1]; + var f1 = 1 + x1; + var f2 = 1 + x2; + return new[] { f1, f2 }; + }; + var init = new[] { 10*Precision.PositiveMachineEpsilon, 1.0 }; + double[] r = Broyden.FindRoot(f, init, 1e-5); + Assert.AreEqual(-1.0 , r[0], 1e-5); + Assert.AreEqual(-1.0, r[1], 1e-5); + } } }