Find a zero of a continuous function using Brent's method.
Finds a zero of a continuous function
var brentq = require( '@stdlib/optimize/base/brentq' );Finds a zero of a continuous function f on the interval [a, b].
function f( x ) {
return ( x * x ) - 1;
}
var root = brentq( f, 0, 2 );
// returns 1.0The function accepts the following options:
- maxIter: maximum number of iterations. Default:
100. - xtol: absolute tolerance. Default:
2e-12. - rtol: relative tolerance. Default:
8.88e-16.
var sin = require( '@stdlib/math/base/special/sin' );
var brentq = require( '@stdlib/optimize/base/brentq' );
function f( x ) {
return sin( x );
}
var root = brentq( f, 3.0, 3.2 );
console.log( root );
// => 3.141592653589793