diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/README.md b/lib/node_modules/@stdlib/optimize/base/brentq/README.md
new file mode 100644
index 000000000000..d70107cde604
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/README.md
@@ -0,0 +1,101 @@
+
+
+# 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
+
+```javascript
+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]`.
+
+```javascript
+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
+
+
+
+```javascript
+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
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/benchmark/benchmark.js b/lib/node_modules/@stdlib/optimize/base/brentq/benchmark/benchmark.js
new file mode 100644
index 000000000000..1c76dca9e4a9
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/benchmark/benchmark.js
@@ -0,0 +1,52 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var bench = require( '@stdlib/bench' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pkg = require( './../package.json' ).name;
+var brentq = require( './../lib' );
+
+
+// MAIN //
+
+bench( pkg, function benchmark( b ) {
+ var root;
+ var i;
+
+ function f( x ) {
+ return ( x * x ) - 1.0;
+ }
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ root = brentq( f, 0.0, 2.0 );
+ if ( isnan( root ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( root ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/docs/repl.txt b/lib/node_modules/@stdlib/optimize/base/brentq/docs/repl.txt
new file mode 100644
index 000000000000..f1a4a36d6edb
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/docs/repl.txt
@@ -0,0 +1,35 @@
+
+{{alias}}( f, a, b[, options] )
+ Finds a zero of a continuous function `f` on the interval `[a, b]`.
+
+ Parameters
+ ----------
+ f: Function
+ Objective function.
+ a: number
+ Lower bound.
+ b: number
+ Upper bound.
+ options: Object (optional)
+ Function options.
+ options.maxIter: number (optional)
+ Maximum number of iterations. Default: 100.
+ options.xtol: number (optional)
+ Absolute tolerance. Default: 2e-12.
+ options.rtol: number (optional)
+ Relative tolerance. Default: 8.88e-16.
+
+ Returns
+ -------
+ x: number
+ Zero.
+
+ Examples
+ --------
+ > function f( x ) { return x*x - 1.0; };
+ > {{alias}}( f, 0.0, 2.0 )
+ 1.0
+
+ See Also
+ --------
+
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/docs/types/index.d.ts b/lib/node_modules/@stdlib/optimize/base/brentq/docs/types/index.d.ts
new file mode 100644
index 000000000000..327ae88b73c6
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/docs/types/index.d.ts
@@ -0,0 +1,67 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+// TypeScript Version: 4.1
+
+/**
+* Interface defining options.
+*/
+interface Options {
+ /**
+ * Maximum number of iterations.
+ */
+ maxIter?: number;
+
+ /**
+ * Absolute tolerance.
+ */
+ xtol?: number;
+
+ /**
+ * Relative tolerance.
+ */
+ rtol?: number;
+}
+
+/**
+* Callback function.
+*
+* @param x - input value
+* @returns function value
+*/
+type Unary = ( x: number ) => number;
+
+/**
+* Finds a zero of a continuous function `f` on the interval `[a, b]`.
+*
+* @param f - objective function
+* @param a - lower bound
+* @param b - upper bound
+* @param options - function options
+* @returns zero
+*
+* @example
+* function f( x ) {
+* return x * x - 1.0;
+* }
+* var v = brentq( f, 0.0, 2.0 );
+* // returns 1.0
+*/
+declare function brentq( f: Unary, a: number, b: number, options?: Options ): number;
+
+export = brentq;
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/docs/types/test.ts b/lib/node_modules/@stdlib/optimize/base/brentq/docs/types/test.ts
new file mode 100644
index 000000000000..8a14ba5ed7d9
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/docs/types/test.ts
@@ -0,0 +1,74 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import brentq = require( './index' );
+
+/**
+* Callback function.
+*
+* @param x - input value
+* @returns result
+*/
+function f( x: number ): number {
+ return x * x - 1.0;
+}
+
+// TESTS //
+
+// The function returns a number...
+{
+ brentq( f, 0.0, 2.0 ); // $ExpectType number
+ brentq( f, 0.0, 2.0, { 'maxIter': 20 } ); // $ExpectType number
+}
+
+// The compiler throws an error if the function is provided an invalid first argument...
+{
+ brentq( true, 0.0, 2.0 ); // $ExpectError
+ brentq( false, 0.0, 2.0 ); // $ExpectError
+ brentq( 5, 0.0, 2.0 ); // $ExpectError
+ brentq( [], 0.0, 2.0 ); // $ExpectError
+ brentq( {}, 0.0, 2.0 ); // $ExpectError
+ brentq( 'abc', 0.0, 2.0 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an invalid second argument...
+{
+ brentq( f, true, 2.0 ); // $ExpectError
+ brentq( f, false, 2.0 ); // $ExpectError
+ brentq( f, [], 2.0 ); // $ExpectError
+ brentq( f, {}, 2.0 ); // $ExpectError
+ brentq( f, 'abc', 2.0 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an invalid third argument...
+{
+ brentq( f, 0.0, true ); // $ExpectError
+ brentq( f, 0.0, false ); // $ExpectError
+ brentq( f, 0.0, [] ); // $ExpectError
+ brentq( f, 0.0, {} ); // $ExpectError
+ brentq( f, 0.0, 'abc' ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an invalid options argument...
+{
+ brentq( f, 0.0, 2.0, true ); // $ExpectError
+ brentq( f, 0.0, 2.0, false ); // $ExpectError
+ brentq( f, 0.0, 2.0, 5 ); // $ExpectError
+ brentq( f, 0.0, 2.0, [] ); // $ExpectError
+ brentq( f, 0.0, 2.0, 'abc' ); // $ExpectError
+}
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/examples/index.js b/lib/node_modules/@stdlib/optimize/base/brentq/examples/index.js
new file mode 100644
index 000000000000..f5b8c5152ea5
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/examples/index.js
@@ -0,0 +1,44 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var pow = require( '@stdlib/math/base/special/pow' );
+var sin = require( '@stdlib/math/base/special/sin' );
+var brentq = require( './../lib' );
+
+function f( x ) {
+ return pow( x, 3 ) - ( 2.0 * x ) - 5.0;
+}
+
+var root = brentq( f, 2.0, 3.0 );
+console.log( 'f(x) = x^3 - 2x - 5' );
+console.log( 'Root: %d', root );
+console.log( 'f(root): %d', f( root ) );
+
+// Example with options
+function g( x ) {
+ return sin( x );
+}
+
+root = brentq( g, 3.0, 4.0, {
+ 'xtol': 1e-4
+});
+console.log( '\nf(x) = sin(x)' );
+console.log( 'Root matching 3.14 on [3, 4] with xtol 1e-4: %d', root );
+console.log( 'f(root): %d', g( root ) );
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/lib/index.js b/lib/node_modules/@stdlib/optimize/base/brentq/lib/index.js
new file mode 100644
index 000000000000..84c99c30edb7
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/lib/index.js
@@ -0,0 +1,44 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+/**
+* Find a zero of a continuous function using Brent's method.
+*
+* @module @stdlib/optimize/base/brentq
+*
+* @example
+* var brentq = require( '@stdlib/optimize/base/brentq' );
+*
+* function f( x ) {
+* return Math.sin( x );
+* }
+*
+* var root = brentq( f, 3.0, 3.2 );
+* // returns ~3.14
+*/
+
+// MODULES //
+
+var main = require( './main.js' );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/lib/main.js b/lib/node_modules/@stdlib/optimize/base/brentq/lib/main.js
new file mode 100644
index 000000000000..5f106bd47fb5
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/lib/main.js
@@ -0,0 +1,205 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var isFunction = require( '@stdlib/assert/is-function' );
+var isNumber = require( '@stdlib/assert/is-number' );
+var format = require( '@stdlib/string/format' );
+var abs = require( '@stdlib/math/base/special/abs' );
+var EPS = require( '@stdlib/constants/float64/eps' );
+
+
+// MAIN //
+
+/**
+* Finds a zero of a continuous function `f` on the interval `[a, b]`.
+*
+* @param {Function} f - objective function
+* @param {number} a - lower bound
+* @param {number} b - upper bound
+* @param {Options} [options] - function options
+* @param {number} [options.maxIter=100] - maximum number of iterations
+* @param {number} [options.xtol=2e-12] - absolute tolerance
+* @param {number} [options.rtol=8.88e-16] - relative tolerance
+* @throws {TypeError} first argument must be a function
+* @throws {TypeError} second argument must be a number
+* @throws {TypeError} third argument must be a number
+* @throws {TypeError} options argument must be an object
+* @throws {Error} function values at the interval endpoints must have opposite signs
+* @returns {number} zero
+*
+* @example
+* function f( x ) {
+* return x * x - 1.0;
+* }
+* var v = brentq( f, 0.0, 2.0 );
+* // returns 1.0
+*/
+function brentq( f, a, b, options ) {
+ var maxIter;
+ var delta; // tolerance
+ var xpre;
+ var xcur;
+ var xblk;
+ var fpre;
+ var fcur;
+ var fblk;
+ var spre;
+ var scur;
+ var sbis;
+ var stry;
+ var dpre;
+ var dblk;
+ var xtol;
+ var rtol;
+ var i;
+
+ if ( !isFunction( f ) ) {
+ throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', f ) );
+ }
+ if ( !isNumber( a ) ) {
+ throw new TypeError( format( 'invalid argument. Second argument must be a number. Value: `%s`.', a ) );
+ }
+ if ( !isNumber( b ) ) {
+ throw new TypeError( format( 'invalid argument. Third argument must be a number. Value: `%s`.', b ) );
+ }
+ maxIter = 100;
+ xtol = 2.0e-12;
+ rtol = 4.0 * EPS;
+
+ if ( arguments.length > 3 ) {
+ if ( typeof options !== 'object' || options === null || Array.isArray( options ) ) {
+ throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
+ }
+ if ( options.maxIter !== void 0 ) {
+ maxIter = options.maxIter;
+ }
+ if ( options.xtol !== void 0 ) {
+ xtol = options.xtol;
+ }
+ if ( options.rtol !== void 0 ) {
+ rtol = options.rtol;
+ }
+ }
+
+ xpre = a;
+ xcur = b;
+ xblk = 0.0;
+ fblk = 0.0;
+ spre = 0.0;
+ scur = 0.0;
+
+ fpre = f( xpre );
+ fcur = f( xcur );
+
+ if ( fpre === 0.0 ) {
+ return xpre;
+ }
+ if ( fcur === 0.0 ) {
+ return xcur;
+ }
+ if ( ( fpre > 0.0 && fcur > 0.0 ) || ( fpre < 0.0 && fcur < 0.0 ) ) {
+ throw new Error( 'invalid arguments. Function values at the interval endpoints must have opposite signs.' );
+ }
+
+ for ( i = 0; i < maxIter; i++ ) {
+ if (
+ fpre !== 0.0 &&
+ fcur !== 0.0 &&
+ ( ( ( fpre > 0.0 ) && ( fcur < 0.0 ) ) || ( ( fpre < 0.0 ) && ( fcur > 0.0 ) ) )
+ ) {
+ // Signs are different
+ xblk = xpre;
+ fblk = fpre;
+ spre = xcur - xpre;
+ scur = spre;
+ }
+ if ( abs( fblk ) < abs( fcur ) ) {
+ xpre = xcur;
+ xcur = xblk;
+ xblk = xpre;
+
+ fpre = fcur;
+ fcur = fblk;
+ fblk = fpre;
+ }
+
+ // delta = (xtol + rtol*fabs(xcur))/2;
+ delta = ( xtol + ( rtol * abs( xcur ) ) ) / 2.0;
+
+ sbis = ( xblk - xcur ) / 2.0;
+
+ if ( fcur === 0.0 || abs( sbis ) < delta ) {
+ return xcur;
+ }
+
+ if ( abs( spre ) > delta && abs( fcur ) < abs( fpre ) ) {
+ if ( xpre === xblk ) {
+ // Interpolate
+ stry = ( -fcur * ( xcur - xpre ) ) / ( fcur - fpre );
+ } else {
+ // Extrapolate
+ dpre = ( fpre - fcur ) / ( xpre - xcur );
+ dblk = ( fblk - fcur ) / ( xblk - xcur );
+ stry = ( -fcur * ( ( fblk * dblk ) - ( fpre * dpre ) ) ) /
+ ( dblk * dpre * ( fblk - fpre ) );
+ }
+
+ // Check if short step is acceptable
+ // 2*fabs(stry) < MIN(fabs(spre), 3*fabs(sbis) - delta)
+ if (
+ 2.0 * abs( stry ) <
+ ( ( abs( spre ) < ( ( 3.0 * abs( sbis ) ) - delta ) ) ?
+ abs( spre ) :
+ ( ( 3.0 * abs( sbis ) ) - delta ) )
+ ) {
+ // Good short step
+ spre = scur;
+ scur = stry;
+ } else {
+ // Bisect
+ spre = sbis;
+ scur = sbis;
+ }
+ } else {
+ // Bisect
+ spre = sbis;
+ scur = sbis;
+ }
+
+ xpre = xcur;
+ fpre = fcur;
+
+ if ( abs( scur ) > delta ) {
+ xcur += scur;
+ } else {
+ xcur += ( sbis > 0.0 ) ? delta : -delta;
+ }
+
+ fcur = f( xcur );
+ }
+ return xcur;
+}
+
+
+// EXPORTS //
+
+module.exports = brentq;
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/package.json b/lib/node_modules/@stdlib/optimize/base/brentq/package.json
new file mode 100644
index 000000000000..7f8af3e04306
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/package.json
@@ -0,0 +1,62 @@
+{
+ "name": "@stdlib/optimize/base/brentq",
+ "version": "0.0.0",
+ "description": "Find a root of a continuous function using Brent's method.",
+ "license": "Apache-2.0",
+ "author": {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ },
+ "contributors": [
+ {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ }
+ ],
+ "main": "./lib",
+ "directories": {
+ "benchmark": "./benchmark",
+ "doc": "./docs",
+ "example": "./examples",
+ "lib": "./lib",
+ "test": "./test"
+ },
+ "types": "./docs/types",
+ "scripts": {},
+ "homepage": "https://github.com/stdlib-js/stdlib",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/stdlib-js/stdlib.git"
+ },
+ "bugs": {
+ "url": "https://github.com/stdlib-js/stdlib/issues"
+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "engines": {
+ "node": ">=0.10.0",
+ "npm": ">2.7.0"
+ },
+ "os": [
+ "aix",
+ "darwin",
+ "freebsd",
+ "linux",
+ "macos",
+ "openbsd",
+ "sunos",
+ "win32",
+ "windows"
+ ],
+ "keywords": [
+ "stdlib",
+ "optimize",
+ "brent",
+ "brentq",
+ "root",
+ "find",
+ "zero",
+ "math",
+ "mathematics"
+ ]
+}
diff --git a/lib/node_modules/@stdlib/optimize/base/brentq/test/test.js b/lib/node_modules/@stdlib/optimize/base/brentq/test/test.js
new file mode 100644
index 000000000000..9e0e0798e611
--- /dev/null
+++ b/lib/node_modules/@stdlib/optimize/base/brentq/test/test.js
@@ -0,0 +1,241 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var tape = require( 'tape' );
+var sin = require( '@stdlib/math/base/special/sin' );
+var abs = require( '@stdlib/math/base/special/abs' );
+var PI = require( '@stdlib/constants/float64/pi' );
+var brentq = require( './../lib' );
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.equal( typeof brentq, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function throws an error if provided an invalid first argument', function test( t ) {
+ var values;
+ var i;
+
+ values = [
+ '5',
+ 5,
+ NaN,
+ true,
+ null,
+ void 0,
+ undefined,
+ [],
+ {}
+ ];
+
+ for ( i = 0; i < values.length; i++ ) {
+ t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] );
+ }
+ t.end();
+
+ function badValue( value ) {
+ return function badValue() {
+ brentq( value, 0.0, 1.0 );
+ };
+ }
+});
+
+tape( 'the function throws an error if provided an invalid second argument', function test( t ) {
+ var values;
+ var i;
+
+ function f( x ) {
+ return x;
+ }
+
+ values = [
+ '5',
+ true,
+ null,
+ undefined,
+ [],
+ {}
+ ];
+
+ for ( i = 0; i < values.length; i++ ) {
+ t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] );
+ }
+ t.end();
+
+ function badValue( value ) {
+ return function badValue() {
+ brentq( f, value, 1.0 );
+ };
+ }
+});
+
+tape( 'the function throws an error if provided an invalid third argument', function test( t ) {
+ var values;
+ var i;
+
+ function f( x ) {
+ return x;
+ }
+
+ values = [
+ '5',
+ true,
+ null,
+ undefined,
+ [],
+ {}
+ ];
+
+ for ( i = 0; i < values.length; i++ ) {
+ t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] );
+ }
+ t.end();
+
+ function badValue( value ) {
+ return function badValue() {
+ brentq( f, 0.0, value );
+ };
+ }
+});
+
+tape( 'the function throws an error if provided an invalid options argument', function test( t ) {
+ var values;
+ var i;
+
+ function f( x ) {
+ return x;
+ }
+
+ values = [
+ '5',
+ 5,
+ true,
+ [],
+ NaN
+ ];
+
+ for ( i = 0; i < values.length; i++ ) {
+ t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] );
+ }
+ t.end();
+
+ function badValue( value ) {
+ return function badValue() {
+ brentq( f, 0.0, 1.0, value );
+ };
+ }
+});
+
+tape( 'the function throws an error if function values at endpoints do not have opposite signs', function test( t ) {
+ function f( x ) {
+ return x * x;
+ }
+ t.throws( function bad() {
+ brentq( f, 1.0, 2.0 );
+ }, Error, 'throws error' );
+ t.end();
+});
+
+tape( 'the function finds the root of a polynomial', function test( t ) {
+ var root;
+ var tol;
+
+ function f( x ) {
+ return ( x * x ) - 1.0;
+ }
+
+ tol = 1.0e-12;
+ root = brentq( f, 0.0, 2.0, {
+ 'xtol': tol
+ });
+ t.ok( abs( root - 1.0 ) <= tol, 'root is within tolerance' );
+
+ root = brentq( f, -2.0, 0.0, {
+ 'xtol': tol
+ });
+ t.ok( abs( root + 1.0 ) <= tol, 'root is within tolerance' );
+
+ t.end();
+});
+
+tape( 'the function finds the root of sin(x)', function test( t ) {
+ var root;
+ var tol;
+
+ function f( x ) {
+ return sin( x );
+ }
+
+ tol = 1.0e-12;
+
+ // Root at PI (~3.14159)
+ root = brentq( f, 3.0, 4.0, {
+ 'xtol': tol
+ });
+ t.ok( abs( root - PI ) <= tol, 'root is within tolerance' );
+ t.end();
+});
+
+tape( 'the function returns the exact root if found immediately (endpoints)', function test( t ) {
+ var root;
+
+ function f( x ) {
+ return ( x * x ) - 1.0;
+ }
+ root = brentq( f, 1.0, 2.0 );
+ t.equal( root, 1.0, 'returns bracket endpoint' );
+
+ root = brentq( f, 0.0, 1.0 );
+ t.equal( root, 1.0, 'returns bracket endpoint' );
+ t.end();
+});
+
+tape( 'the function respects relative tolerance', function test( t ) {
+ var expected;
+ var root;
+ var rtol;
+
+ function f( x ) {
+ // Root at x = 1000
+ return ( x * x ) - 1000000.0;
+ }
+
+ // For large roots, rtol dominates xtol (default 2e-12)
+ // |x - root| <= xtol + rtol*|root|
+ // If we set rtol to 1e-4, then error can be up to 1e-4 * 1000 = 0.1
+ rtol = 1.0e-4;
+ expected = 1000.0;
+
+ root = brentq( f, 900.0, 1100.0, {
+ 'rtol': rtol,
+ 'xtol': 0.0 // Disable xtol to test rtol
+ });
+
+ // Note: the convergence check uses `delta` which is half the tolerance interval.
+
+ // The condition in the code is `|x - x_exact| <= delta`.
+
+ // Delta = (xtol + rtol*|xcur|)/2
+
+ // So we expect error <= (rtol * |root|)/2 approximately.
+ t.ok( abs( root - expected ) <= ( rtol * abs( expected ) ), 'root satisfies relative tolerance' );
+ t.end();
+});