FiniteDifferenceMatrices.jl

Build Status Stable Dev

A Julia package for discrete approximations of differential operators

Install

Run the following code on the to install this package.

import Pkg; Pkg.add(url="https://github.com/ohno/FiniteDifferenceMatrices.jl.git")

Usage

Run the following code before each use.

using FiniteDifferenceMatrices

A central finite difference of the second-order derivative is

\[\frac{\mathrm{d}^{2}f}{\mathrm{d} x^{2}}(x) = \frac{f(x+\Delta x) - 2f(x) + f(x-\Delta x)}{\Delta x^{2}} + O(\Delta x^{2}).\]

julia> fdcoefficient(n=2, m=2, d=:c, t=Int)Dict{Int64, Int64} with 3 entries:
  0  => -2
  -1 => 1
  1  => 1

A discrete approximation of the second-order differential operator is

\[\frac{\mathrm{d}^2}{\mathrm{d} x^2} \simeq \frac{1}{\Delta x^2} \left(\begin{array}{ccccccc} -2 & 1 & 0 & \ldots & 0 & 0 & 0 \\ 1 & -2 & 1 & \ldots & 0 & 0 & 0 \\ 0 & 1 & -2 & \ldots & 0 & 0 & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots \\ 0 & 0 & 0 & \ldots & -2 & 1 & 0 \\ 0 & 0 & 0 & \ldots & 1 & -2 & 1 \\ 0 & 0 & 0 & \ldots & 0 & 1 & -2 \end{array}\right).\]

julia> fdmatrix(5, n=2, m=2, d=:c, h=1//1)5×5 SparseArrays.SparseMatrixCSC{Rational{Int64}, Int64} with 13 stored entries:
 -2   1   ⋅   ⋅   ⋅
  1  -2   1   ⋅   ⋅
  ⋅   1  -2   1   ⋅
  ⋅   ⋅   1  -2   1
  ⋅   ⋅   ⋅   1  -2

Please see Tables, Examples and API reference for more information.

Developer's Guide

There are several tools for developers.

git clone https://github.com/ohno/FiniteDifferenceMatrices.jl.git
cd FiniteDifferenceMatrices.jl
julia
julia> include("dev/revice.jl")
julia> include("dev/test.jl")
julia> include("dev/docs.jl")

API reference