mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
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:
parent
02328287cb
commit
0620a19eb9
1 changed files with 6 additions and 1 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue