Skip to content

Latest commit

 

History

History
101 lines (62 loc) · 2.11 KB

File metadata and controls

101 lines (62 loc) · 2.11 KB

brentq

Find a zero of a continuous function using Brent's method.

Finds a zero of a continuous function $f$ on the interval $\lbrack a, b \rbrack$ where the sign of $f(a)$ and $f(b)$ must be opposite.

Usage

var brentq = require( '@stdlib/optimize/base/brentq' );

brentq( f, a, b[, options] )

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.0

The 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.

Examples

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