34

12

5

9

# FiniteDifferences.jl: Finite Difference Methods

FiniteDifferences.jl estimates derivatives with finite differences.

## 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 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)
-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
``````

## FDM.jl

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

01/17/2018

6 days ago

112 commits