FiniteDifferences.jl estimates derivatives with finite differences.

See also the Python package FDM.

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

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

01/17/2018

17 days ago

127 commits