Liking cljdoc? Tell your friends :D
Clojure only.

fastmath.solver.newton

Newton's method for a root of a function with a known derivative, safeguarded by the bracket.

The new point is the root of the tangent line, which gives a quadratic convergence near a simple root. Here the step is replaced by a bisection step whenever it would leave the bracket or does not converge fast enough, so the method does not fail on a function with a sign change. The derivative is the option :df; without it a central finite difference of order 4 (see fastmath.calculus/derivative) is used, which costs four evaluations of the function per step.

Newton's method for a root of a function with a known derivative, safeguarded by the bracket.

The new point is the root of the tangent line, which gives a quadratic convergence near a simple root. Here the step is replaced by a bisection step whenever it would leave the bracket or does not converge fast enough, so the method does not fail on a function with a sign change. The derivative is the option `:df`; without it a central finite difference of order 4 (see [[fastmath.calculus/derivative]]) is used, which costs four evaluations of the function per step.
raw docstring

newtonclj

(newton f lower upper)
(newton f lower upper options)

Finds a root of f on [lower, upper] with Newton's method safeguarded by the bracket.

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):
    • :df - the first derivative of f, a function of one number returning a number. Default a central finite difference of order 4 (the evaluations of f made by it count to :max-iters).
    • :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 evaluations of f (an integer), default 1200; a call of a derivative is made at most once per evaluation of f. Exceeding the limit throws.
    • :initial-value - the first point, strictly inside the interval, default the middle of the interval.
    • :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. A derivative which is zero, NaN or infinite never stops the search: the step is replaced by a bisection step.

Throws ex-info for an invalid argument (an option which is not a function included), and for a failed solve: no sign change on the interval (:status :no-bracket), NaN function values (:nan), a non number result of f or of a derivative (: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.halley/halley, fastmath.solver.brent/brent.

Finds a root of `f` on `[lower, upper]` with Newton's method safeguarded by the bracket.

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):
    - `:df` - the first derivative of `f`, a function of one number returning a number. Default a central finite difference of order 4 (the evaluations of `f` made by it count to `:max-iters`).
    - `: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 evaluations of `f` (an integer), default `1200`; a call of a derivative is made at most once per evaluation of `f`. Exceeding the limit throws.
    - `:initial-value` - the first point, strictly inside the interval, default the middle of the interval.
    - `: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. A derivative which is zero, `NaN` or infinite never stops the search: the step is replaced by a bisection step.

Throws `ex-info` for an invalid argument (an option which is not a function included), and for a failed solve: no sign change on the interval (`:status :no-bracket`), `NaN` function values (`:nan`), a non number result of `f` or of a derivative (`: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.halley/halley]], [[fastmath.solver.brent/brent]].
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close