The bisection method for a root of a function on an interval with a sign change.
Every step halves the interval, so the number of evaluations is known in advance and the method never fails on a function with a sign change, whatever its shape, jumps included. It is the slowest of the bracketing methods and works on any scale of the root.
The bisection method for a root of a function on an interval with a sign change. Every step halves the interval, so the number of evaluations is known in advance and the method never fails on a function with a sign change, whatever its shape, jumps included. It is the slowest of the bracketing methods and works on any scale of the root.
(bisection f lower upper)(bisection f lower upper options)Finds a root of f on [lower, upper] by halving the interval.
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, enough to reach the floating point resolution on any interval. Exceeding it throws.:initial-value - ignored by this method.: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, the middle of the last interval. A root at an end of the interval is returned after at most two evaluations. At the default tolerance the result is within a few units in the last place; on a jump of the function it is the point of the jump.
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.brent/brent.
Finds a root of `f` on `[lower, upper]` by halving the interval.
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`, enough to reach the floating point resolution on any interval. Exceeding it throws.
- `:initial-value` - ignored by this method.
- `: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, the middle of the last interval. A root at an end of the interval is returned after at most two evaluations. At the default tolerance the result is within a few units in the last place; on a jump of the function it is the point of the jump.
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.brent/brent]].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 |