FDM.assert_approx_equal
— Methodassert_approx_equal(x, y, ε_abs, ε_rel[, desc])
Assert that x
is approximately equal to y
.
Let eps_z = eps_abs / eps_rel
. Call x
and y
small if abs(x) < eps_z
and abs(y) < eps_z
, and call x
and y
large otherwise. If this function returns True
, then it is guaranteed that abs(x - y) < 2 eps_rel max(abs(x), abs(y))
if x
and y
are large, and abs(x - y) < 2 eps_abs
if x
and y
are small.
Arguments
x
: First object to compare.y
: Second object to compare.ε_abs
: Absolute tolerance.ε_rel
: Relative tolerance.desc
: Description of the comparison. Omit or set tofalse
to have no description.
FDM.backward_fdm
— FunctionFDM.Backward(p, q; kwargs...)
backward_fdm(p, q; kwargs...)
Construct a backward finite difference method of order p
to compute the q
th derivative. See FDMethod
for more details.
FDM.central_fdm
— FunctionFDM.Central(p, q; kwargs...)
central_fdm(p, q; kwargs...)
Construct a central finite difference method of order p
to compute the q
th derivative. See FDMethod
for more details.
FDM.fdm
— Methodfdm(m::FDMethod, f, x[, Val(false)]; kwargs...) -> Real
fdm(m::FDMethod, f, x, Val(true); kwargs...) -> Tuple{FDMethod, Real}
Compute the derivative of f
at x
using the finite differencing method m
. The optional Val
argument dictates whether the method should be returned alongside the derivative value, which can be useful for examining the step size used and other such parameters.
The recognized keywords are:
adapt
: The number of adaptive steps to use improve the estimate ofbound
.bound
: Bound on the value of the function and its derivatives atx
.condition
: The condition number. SeeDEFAULT_CONDITION
.eps
: The assumed roundoff error. Defaults toeps()
plusTINY
.
Bounds can't be adaptively computed over nonstandard grids; passing a value for adapt
greater than 0 when m::Nonstandard
results in an error.
Calling FDMethod
objects is equivalent to passing them to fdm
.
Examples
julia> fdm(central_fdm(5, 1), sin, 1; adapt=2)
0.5403023058681039
julia> fdm(central_fdm(2, 1), exp, 0, Val(true))
(FDMethod:
order of method: 2
order of derivative: 1
grid: [-1, 1]
coefficients: [-0.5, 0.5]
roundoff error: 1.42e-14
bounds on derivatives: 1.00e+02
step size: 1.69e-08
accuracy: 1.69e-06
, 1.0000000031817473)
FDM.forward_fdm
— FunctionFDM.Forward(p, q; kwargs...)
forward_fdm(p, q; kwargs...)
Construct a forward finite difference method of order p
to compute the q
th derivative. See FDMethod
for more details.
FDM.DEFAULT_CONDITION
— ConstantFDM.DEFAULT_CONDITION
The default condition number used when computing bounds. It provides amplification of the ∞-norm when passed to the function's derivatives.
FDM.TINY
— ConstantFDM.TINY
A tiny number added to some quantities to ensure that division by 0 does not occur.
FDM.Backward
— TypeFDM.Backward(p, q; kwargs...)
backward_fdm(p, q; kwargs...)
Construct a backward finite difference method of order p
to compute the q
th derivative. See FDMethod
for more details.
FDM.Central
— TypeFDM.Central(p, q; kwargs...)
central_fdm(p, q; kwargs...)
Construct a central finite difference method of order p
to compute the q
th derivative. See FDMethod
for more details.
FDM.FDMethod
— TypeFDMethod
Abstract type for all finite differencing method types. Subtypes of FDMethod
are callable with the signature
method(f, x; kwargs...)
where the keyword arguments can be any of
adapt
: The number of adaptive steps to use improve the estimate ofbound
.bound
: Bound on the value of the function and its derivatives atx
.condition
: The condition number. SeeDEFAULT_CONDITION
.eps
: The assumed roundoff error. Defaults toeps()
plusTINY
.
FDM.Forward
— TypeFDM.Forward(p, q; kwargs...)
forward_fdm(p, q; kwargs...)
Construct a forward finite difference method of order p
to compute the q
th derivative. See FDMethod
for more details.
FDM.History
— TypeHistory
A mutable type that tracks several values during adaptive bound computation.
FDM.Nonstandard
— MethodFDM.Nonstandard(grid, q; kwargs...)
An finite differencing method which is constructed based on a user-defined grid. It is nonstandard in the sense that it represents neither forward, backward, nor central differencing. See FDMethod
for further details.
FDM._jvp
— Method_jvp(fdm, f, x::Vector{<:Real}, ẋ::AbstractVector{<:Real})
Convenience function to compute jacobian(f, x) * ẋ
.
FDM._j′vp
— Method_j′vp(fdm, f, ȳ::AbstractVector{<:Real}, x::Vector{<:Real})
Convenience function to compute jacobian(f, x)' * ȳ
.
FDM.grad
— Methodgrad(fdm, f, x::AbstractVector)
Approximate the gradient of f
at x
using fdm
. Assumes that f(x)
is scalar.
FDM.jacobian
— Methodjacobian(fdm, f, x::AbstractVector{<:Real}, D::Int)
jacobian(fdm, f, x::AbstractVector{<:Real})
Approximate the Jacobian of f
at x
using fdm
. f(x)
must be a length D
vector. If D
is not provided, then f(x)
is computed once to determine the output size.
FDM.jvp
— Methodjvp(fdm, f, x, ẋ)
Compute a Jacobian-vector product with any types of arguments for which to_vec
is defined.
FDM.j′vp
— Methodj′vp(fdm, f, ȳ, x...)
Compute an adjoint with any types of arguments for which to_vec
is defined.
FDM.to_vec
— Methodto_vec(x)
Transform x
into a Vector
, and return a closure which inverts the transformation.