High accuracy derivatives, estimated via numerical finite differences (formerly FDM.jl)
Author JuliaDiff
64 Stars
Updated Last
11 Months Ago
Started In
January 2018

FiniteDifferences.jl: Finite Difference Methods

Build Status PkgEval

Latest Docs Code Style: Blue

FiniteDifferences.jl estimates derivatives with finite differences.

See also the Python package FDM.

FiniteDiff.jl vs FiniteDifferences.jl

FiniteDiff.jl and FiniteDifferences.jl are similar libraries: both calculate approximate derivatives numerically. You should definately use one or the other, rather than the legacy Calculus.jl finite differencing, or reimplementing it yourself. At some point in the future they might merge, or one might depend on the other. Right now here are the differences:

  • FiniteDifferences.jl supports basically any type, where as FiniteDiff.jl supports only array-ish types
  • FiniteDifferences.jl supports higher order approximation
  • FiniteDiff.jl is carefully optimized to minimize allocations
  • FiniteDiff.jl supports coloring vectors for efficient calculation of sparse Jacobians


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

julia> central_fdm(5, 1)(sin, 1) - cos(1)

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

julia> central_fdm(5, 2)(sin, 1) + sin(1)

Construct a FiniteDifferences on a custom grid:

julia> method, report = fdm([-2, 0, 5], 1, report=true)
(FiniteDifferences.method, FiniteDifferencesReport:
  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)

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


This package was formerly called FDM.jl. We recommend users of FDM.jl update to FiniteDifferences.jl.

Required Packages

No packages found.