This namespace contains implementations of various approaches to numerical differentiation.
Each of these methods uses Richardson extrapolation to accelerate convergence, and roundoff error estimation to bail out of the computation when roundoff error threatens to overwhelm the calculation.
For an implementation of forward-mode automatic
differentiation,
see emmy.differential
(for the backing implementation)
and emmy.calculus.derivative
(for the [[emmy.operator/Operator]]
instances that make it pleasant to use this method.)
This namespace contains implementations of various approaches to [numerical differentiation](https://en.wikipedia.org/wiki/Numerical_differentiation). Each of these methods uses [Richardson extrapolation](https://en.wikipedia.org/wiki/Richardson_extrapolation) to accelerate convergence, and roundoff error estimation to bail out of the computation when roundoff error threatens to overwhelm the calculation. For an implementation of [forward-mode automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation), see [[emmy.differential]] (for the backing implementation) and [[emmy.calculus.derivative]] (for the [[emmy.operator/Operator]] instances that make it pleasant to use this method.)
(backward-difference f x)
(backward-difference f x fx)
Returns a single-variable function of a step size h
that calculates the
backward-difference estimate of the first derivative of f
at point x
:
f'(x) = [f(x) - f(x - h)] / h
Optionally accepts a third argument fx == (f x)
, in case you've already
calculated it elsewhere and would like to save a function evaluation.
Returns a single-variable function of a step size `h` that calculates the backward-difference estimate of the first derivative of `f` at point `x`: ``` f'(x) = [f(x) - f(x - h)] / h ``` Optionally accepts a third argument `fx == (f x)`, in case you've already calculated it elsewhere and would like to save a function evaluation.
(central-difference f x)
Returns a single-variable function of a step size h
that calculates the
central-difference estimate of the first derivative of f
at point x
:
f'(x) = [f(x + h) - f(x - h)] / 2h
Returns a single-variable function of a step size `h` that calculates the central-difference estimate of the first derivative of `f` at point `x`: ``` f'(x) = [f(x + h) - f(x - h)] / 2h ```
(central-difference-d2 f x)
(central-difference-d2 f x fx)
Returns a single-variable function of a step size h
that calculates the
central-difference estimate of the second derivative of f
at point x
:
f''(x) = [f(x + h) - 2f(x) + f(x - h)] / h^2
Optionally accepts a third argument fx == (f x)
, in case you've already
calculated it elsewhere and would like to save a function evaluation.
Returns a single-variable function of a step size `h` that calculates the central-difference estimate of the second derivative of `f` at point `x`: f''(x) = [f(x + h) - 2f(x) + f(x - h)] / h^2 Optionally accepts a third argument `fx == (f x)`, in case you've already calculated it elsewhere and would like to save a function evaluation.
(D-numeric f)
(D-numeric f opts)
Takes a function f: R => R
(function of a single real variable), and returns
a new function of x
that approximates the derivative $Df(x)$ (or $D^2f(x)$
if you pass :method :central-d2
).
Returns the estimated value of the derivative at x
. If you pass :info? true
, the fn returns a dictionary of the results of us/seq-limit
:
{:converged? <boolean>
:terms-checked <int>
:result <derivative estimate>}
Make sure to visit emmy.calculus.derivative/D
if you want symbolic or
automatic differentiation.
The returned function will attempt to estimate how many times it can halve the
step size used to estimate the derivative before roundoff error swamps the
calculation, and force the function to return (with :converged? false
, if
you pass :info?
)
D-numeric
takes optional args as its second param. Any of these can be
overridden by passing a second argument to the function returned by
D-numeric
; helpful for setting defaults and then overriding them later.
The returned function passes through these and any other options to
us/seq-limit
, where they control the sequence of richardson
extrapolation-accelerated estimates.
Options:
:method
: one of :central
, :central-d2
, :forward
or :backward
.
:central-d2
forces a second derivative estimate; the other methods configure
a first derivative estimator.
:info?
if false (default), returns the estimated value of x
. If true,
returns a dictionary with more information (see D-numeric
's docstring for
more info.)
:initial-h
: the initial h
to use for derivative estimates before $h o
0$. Defaults to 0.1 * abs(x)
.
:tolerance
: see us/stream-limit
for a discussion of how this value
handles relative vs absolute tolerance. $\sqrt(\epsilon)$ by default, where
$\epsilon$ = machine tolerance.
:maxterms
: the maximum number of terms to consider when hunting for a
derivative estimate. This defaults to an estimate generated internally,
designed to prevent roundoff error from swamping the result. If you want to
disable this feature, set :maxterms
to something moderately large, like
:maxterms 100
. But do so carefully! See the surrounding namespace for a
larger discussion.
Takes a function `f: R => R` (function of a single real variable), and returns a new function of `x` that approximates the derivative $Df(x)$ (or $D^2f(x)$ if you pass `:method :central-d2`). Returns the estimated value of the derivative at `x`. If you pass `:info? true`, the fn returns a dictionary of the results of `us/seq-limit`: ```clojure {:converged? <boolean> :terms-checked <int> :result <derivative estimate>} ``` Make sure to visit [[emmy.calculus.derivative/D]] if you want symbolic or automatic differentiation. ### Roundoff Estimate The returned function will attempt to estimate how many times it can halve the step size used to estimate the derivative before roundoff error swamps the calculation, and force the function to return (with `:converged? false`, if you pass `:info?`) ### Optional Arguments `D-numeric` takes optional args as its second param. Any of these can be overridden by passing a second argument to the function returned by `D-numeric`; helpful for setting defaults and then overriding them later. The returned function passes through these and any other options to `us/seq-limit`, where they control the sequence of richardson extrapolation-accelerated estimates. Options: - `:method`: one of `:central`, `:central-d2`, `:forward` or `:backward`. `:central-d2` forces a second derivative estimate; the other methods configure a first derivative estimator. - `:info?` if false (default), returns the estimated value of `x`. If true, returns a dictionary with more information (see `D-numeric`'s docstring for more info.) - `:initial-h`: the initial `h` to use for derivative estimates before $h o 0$. Defaults to `0.1 * abs(x)`. - `:tolerance`: see `us/stream-limit` for a discussion of how this value handles relative vs absolute tolerance. $\sqrt(\epsilon)$ by default, where $\epsilon$ = machine tolerance. - `:maxterms`: the maximum number of terms to consider when hunting for a derivative estimate. This defaults to an estimate generated internally, designed to prevent roundoff error from swamping the result. If you want to disable this feature, set `:maxterms` to something moderately large, like `:maxterms 100`. But do so carefully! See the surrounding namespace for a larger discussion.
(forward-difference f x)
(forward-difference f x fx)
Returns a single-variable function of a step size h
that calculates the
forward-difference estimate of the the first derivative of f
at point x
:
f'(x) = [f(x + h) - f(x)] / h
Optionally accepts a third argument fx == (f x)
, in case you've already
calculated it elsewhere and would like to save a function evaluation.
Returns a single-variable function of a step size `h` that calculates the forward-difference estimate of the the first derivative of `f` at point `x`: ``` f'(x) = [f(x + h) - f(x)] / h ``` Optionally accepts a third argument `fx == (f x)`, in case you've already calculated it elsewhere and would like to save a function evaluation.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close