The secant method for a root of a function, started from the ends of an interval.
The new point is the root of the line through the last two points. The method has superlinear convergence (order about 1.62) but, unlike the bracketing methods, it does not keep a bracket: the iteration can leave the interval and run away from the root. It is a failure here, never a result: a result outside the interval, a flat step or a point which is not a root throws.
The secant method for a root of a function, started from the ends of an interval. The new point is the root of the line through the last two points. The method has superlinear convergence (order about 1.62) but, unlike the bracketing methods, it does not keep a bracket: the iteration can leave the interval and run away from the root. It is a failure here, never a result: a result outside the interval, a flat step or a point which is not a root throws.
(secant f lower upper)(secant f lower upper options)Finds a root of f with the secant method started from the ends of [lower, upper].
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. The result has to lie in the interval, the iteration itself may leave it.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 - 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. A root at an end of the interval is returned after at most two evaluations. The search stops when the step is within the tolerance and the function changes the sign within two tolerances of the point.
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), the evaluation limit (:max-evals) or a runaway iteration (:diverged): an iterate is not finite, two consecutive values are equal, or the step converged to a point which is not a root of the interval. The function is evaluated outside the interval when an iterate leaves it, which gives :nan when the function is not defined there. The data of the exception holds the :status and a few scalars.
See also fastmath.solver/find-root, fastmath.solver.brent/brent, fastmath.solver.illinois/illinois.
Finds a root of `f` with the secant method started from the ends of `[lower, upper]`.
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. The result has to lie in the interval, the iteration itself may leave it.
- `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` - 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. A root at an end of the interval is returned after at most two evaluations. The search stops when the step is within the tolerance and the function changes the sign within two tolerances of the point.
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`), the evaluation limit (`:max-evals`) or a runaway iteration (`:diverged`): an iterate is not finite, two consecutive values are equal, or the step converged to a point which is not a root of the interval. The function is evaluated outside the interval when an iterate leaves it, which gives `:nan` when the function is not defined there. The data of the exception holds the `:status` and a few scalars.
See also [[fastmath.solver/find-root]], [[fastmath.solver.brent/brent]], [[fastmath.solver.illinois/illinois]].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 |