Use False Position method as fall back in Newton-Raphson method, for accurate results in rare sitatuations wher the fast Newton-Raphson method fails.

This commit is contained in:
Jürg Lehni 2011-03-20 02:01:17 +00:00
parent 02328287cb
commit 0620a19eb9

View file

@ -74,6 +74,9 @@ var Numerical = new function() {
return A * sum; return A * sum;
}, },
/**
* Newton-Raphson Method Using Derivative
*/
findRootNewton: function(f, fd, a, b, n, tol) { findRootNewton: function(f, fd, a, b, n, tol) {
var x = 0.5 * (a + b); var x = 0.5 * (a + b);
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
@ -82,7 +85,9 @@ var Numerical = new function() {
if (Math.abs(dx) < tol) if (Math.abs(dx) < tol)
return x; 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) { findRootFalsePosition: function(f, a, b, n, tol) {