Estimate derivatives with finite differences
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

FDM.jl: Finite Difference Methods

Build Status Windows Build status FDM FDM codecov.io Latest Docs

FDM.jl estimates derivatives with finite differences.

See also FDM.

Examples

Compute the first derivative of sin with a 5th order central method:

julia> central_fdm(5, 1)(sin, 1) - cos(1)
-1.247890679678676e-13

Compute the second derivative of sin with a 5th order central method:

julia> central_fdm(5, 2)(sin, 1) + sin(1)
9.747314066999024e-12

Construct a FDM on a custom grid:

julia> method, report = fdm([-2, 0, 5], 1, report=true)
(FDM.method, FDMReport:
  order of method:       3
  order of derivative:   1
  grid:                  [-2, 0, 5]
  coefficients:          [-0.357143, 0.3, 0.0571429]
  roundoff error:        2.22e-16
  bounds on derivatives: 1.00e+00
  step size:             3.62e-06
  accuracy:              6.57e-11
)

julia> method(sin, 1) - cos(1)
-2.05648831297367e-11

Compute a directional derivative:

julia> f(x) = sum(x)
f (generic function with 1 method)

julia> central_fdm(5, 1)(ε -> f([1, 1, 1] + ε * [1, 2, 3]), 0) - 6
-2.922107000813412e-13