https://github.com/ohno/finitedifferencematrices.jl
A Julia package for discrete approximations of differential operators
https://github.com/ohno/finitedifferencematrices.jl
finite-difference finite-difference-method julia
Last synced: 10 months ago
JSON representation
A Julia package for discrete approximations of differential operators
- Host: GitHub
- URL: https://github.com/ohno/finitedifferencematrices.jl
- Owner: ohno
- License: mit
- Created: 2024-07-10T10:14:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-03T11:27:24.000Z (over 1 year ago)
- Last Synced: 2025-04-05T08:16:42.374Z (10 months ago)
- Topics: finite-difference, finite-difference-method, julia
- Language: Julia
- Homepage: https://ohno.github.io/FiniteDifferenceMatrices.jl/
- Size: 445 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FiniteDifferenceMatrices.jl
[](https://github.com/ohno/FiniteDifferenceMatrices.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://ohno.github.io/FiniteDifferenceMatrices.jl/stable/)
[](https://ohno.github.io/FiniteDifferenceMatrices.jl/dev/)
A Julia package for discrete approximations of differential operators
## Install
Run the following code on the to install this package.
```julia
import Pkg; Pkg.add(url="https://github.com/ohno/FiniteDifferenceMatrices.jl.git")
```
## Usage
Run the following code before each use.
```@example index
using FiniteDifferenceMatrices
```
A central finite difference of the second-order derivative is
```math
\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-repl
julia> fdcoefficient(n=2, m=2, d=:c)
Dict{Int64, Rational{Int64}} with 3 entries:
0 => -2//1
-1 => 1//1
1 => 1//1
```
A discrete approximation of the second-order differential operator is
```math
\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-repl
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//1 ⋅ ⋅ ⋅
1//1 -2//1 1//1 ⋅ ⋅
⋅ 1//1 -2//1 1//1 ⋅
⋅ ⋅ 1//1 -2//1 1//1
⋅ ⋅ ⋅ 1//1 -2//1
```
Please see [Tables](https://ohno.github.io/FiniteDifferenceMatrices.jl/dev/tables/), [Examples](https://ohno.github.io/FiniteDifferenceMatrices.jl/dev/examples/) and [API reference](https://ohno.github.io/FiniteDifferenceMatrices.jl/dev/API/) for more information.
## Developer's Guide
There are several tools for developers.
```sh
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")
```