From 0620a19eb9411454bb0c19e6da8982d052982ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 20 Mar 2011 02:01:17 +0000 Subject: [PATCH] Use False Position method as fall back in Newton-Raphson method, for accurate results in rare sitatuations wher the fast Newton-Raphson method fails. --- src/util/Numerical.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util/Numerical.js b/src/util/Numerical.js index 916c02c0..f6942345 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -74,6 +74,9 @@ var Numerical = new function() { return A * sum; }, + /** + * Newton-Raphson Method Using Derivative + */ findRootNewton: function(f, fd, a, b, n, tol) { var x = 0.5 * (a + b); for (var i = 0; i < n; i++) { @@ -82,7 +85,9 @@ var Numerical = new function() { if (Math.abs(dx) < tol) return x; } - return x; + // If we did not succeed, fall back on False Position method for + // accurate results. + return Numerical.findRootFalsePosition(f, a, b, n, tol); }, findRootFalsePosition: function(f, a, b, n, tol) {