Brent's method for a root of a function on an interval with a sign change.
The method combines bisection, the secant method and inverse quadratic interpolation. It always keeps a bracket of the root, converges at least as fast as bisection and usually superlinearly. It is the default method of fastmath.solver/find-root.
Brent's method for a root of a function on an interval with a sign change. The method combines bisection, the secant method and inverse quadratic interpolation. It always keeps a bracket of the root, converges at least as fast as bisection and usually superlinearly. It is the default method of [[fastmath.solver/find-root]].
(brent f lower upper)(brent f lower upper options)Finds a root of f on [lower, upper] with Brent's method.
Parameters:
f (function): a function of one number returning a number; it has to change the sign on the interval.lower, upper (finite numbers): ends of the interval; reversed ends are swapped.options (map, optional):
:absolute-accuracy - absolute tolerance of the root, default 1.0e-300.:relative-accuracy - tolerance relative to the root, default four times the machine epsilon. The root is found within absolute + relative * |root|.:max-iters - limit of function evaluations (an integer), default 1200. Exceeding it throws.:initial-value - the first point of the search, strictly inside the interval, default the plain bracket. The point replaces the end of the interval which has the same sign.:info? - when truthy, returns the map {:root :evaluations :status} instead of the root, and returns the failure status instead of throwing. Default false.Returns the root as a double. A root at an end of the interval is returned after at most two evaluations. Function values are never used to stop the search: only the bracket decides, so a function with tiny values is solved as accurately as any other.
Throws ex-info for an invalid argument, and for a failed solve: no sign change on the interval (:status :no-bracket), NaN function values (:nan), a non number result (:invalid-result) or the evaluation limit (:max-evals). The data of the exception holds the :status and a few scalars.
See also fastmath.solver/find-root, fastmath.solver.bisection/bisection, fastmath.solver.toms748/toms748.
Finds a root of `f` on `[lower, upper]` with Brent's method.
Parameters:
- `f` (function): a function of one number returning a number; it has to change the sign on the interval.
- `lower`, `upper` (finite numbers): ends of the interval; reversed ends are swapped.
- `options` (map, optional):
- `:absolute-accuracy` - absolute tolerance of the root, default `1.0e-300`.
- `:relative-accuracy` - tolerance relative to the root, default four times the machine epsilon. The root is found within `absolute + relative * |root|`.
- `:max-iters` - limit of function evaluations (an integer), default `1200`. Exceeding it throws.
- `:initial-value` - the first point of the search, strictly inside the interval, default the plain bracket. The point replaces the end of the interval which has the same sign.
- `:info?` - when truthy, returns the map `{:root :evaluations :status}` instead of the root, and returns the failure status instead of throwing. Default `false`.
Returns the root as a double. A root at an end of the interval is returned after at most two evaluations. Function values are never used to stop the search: only the bracket decides, so a function with tiny values is solved as accurately as any other.
Throws `ex-info` for an invalid argument, and for a failed solve: no sign change on the interval (`:status :no-bracket`), `NaN` function values (`:nan`), a non number result (`:invalid-result`) or the evaluation limit (`:max-evals`). The data of the exception holds the `:status` and a few scalars.
See also [[fastmath.solver/find-root]], [[fastmath.solver.bisection/bisection]], [[fastmath.solver.toms748/toms748]].cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |