https://github.com/QuantEcon/SimpleDifferentialOperators.jl
  
  
    Library for simple upwind finite differences 
    https://github.com/QuantEcon/SimpleDifferentialOperators.jl
  
differential-equations julia mathematics
        Last synced: 6 months ago 
        JSON representation
    
Library for simple upwind finite differences
- Host: GitHub
 - URL: https://github.com/QuantEcon/SimpleDifferentialOperators.jl
 - Owner: QuantEcon
 - License: mit
 - Created: 2019-02-11T18:00:21.000Z (over 6 years ago)
 - Default Branch: master
 - Last Pushed: 2020-05-12T15:36:27.000Z (over 5 years ago)
 - Last Synced: 2024-10-30T04:30:02.961Z (about 1 year ago)
 - Topics: differential-equations, julia, mathematics
 - Language: Julia
 - Size: 4.64 MB
 - Stars: 12
 - Watchers: 6
 - Forks: 2
 - Open Issues: 24
 - 
            Metadata Files:
            
- Readme: README.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- awesome-sciml - QuantEcon/SimpleDifferentialOperators.jl: Library for simple upwind finite differences
 
README
          # SimpleDifferentialOperators
[](https://travis-ci.com/QuantEcon/SimpleDifferentialOperators.jl)
[](https://codecov.io/gh/QuantEcon/SimpleDifferentialOperators.jl)
[](https://QuantEcon.github.io/SimpleDifferentialOperators.jl/stable)
## Overview
This is a package to return discretized differential operators subject to various boundary conditions.  It is intended to be a "simple" stopgap as more advanced implementations (e.g. [DiffEqOperators.jl](https://github.com/JuliaDiffEq/DiffEqOperators.jl/) ) mature.  This package is also not intended to provide a "higher-level" interface for constructing the equations.  See [EconPDEs.jl](https://github.com/matthieugomez/EconPDEs.jl/) for a package intended to make translation of the sorts of equations used in economics more direct.
### Example
#### Bellman equation
Consider constructing the corresponding infinitesimal generator for the following stochastic differential equation:

with some constant `μ` and `σ >= 0`, and `W_t` Brownian Motion subject, with reflecting barriers at `x=0` and `x=1`, i.e., `v'(0) = v'(1) = 0`.
If the payoff is in state `x` is `f(x)` and `ρ` is the discount rate, then the bellman equation for the expected present discounted value of payoffs fulfills
%20%3D%20f(x)%20%2B%20%5Cpartial_x%20v(x)%20%2B%20%5Cfrac%7B%5Csigma%5E2%7D%7B2%7D%5Cpartial_%7Bxx%7Dv(x)%24)
subject to %20%3D%200%2C%5C%2C%20%5Cpartial_x%20v(1)%20%3D%200%20%24)
Written in operator form, define the differential operators

then the Bellman equation can be written as
%20%3D%20f(x)%24)
This package provides components to discretize differential operators.  To implement directly,
```julia
using SimpleDifferentialOperators, LinearAlgebra
f(x) = x^2
μ = -0.1 # constant negative drift
σ = 0.1
ρ = 0.05
M = 100 # size of interior nodes
x̄ = range(0.0, 1.0, length = (M+2)) # extended grid
x = interiornodes(x̄) # interior grid
# discretize L = ρ - μ D_x - σ^2 / 2 D_xx on the interior
# subject to reflecting barriers at 0 and 1
bc = (Reflecting(), Reflecting())
L_x = μ*L₁₋bc(x̄, bc) - σ^2 / 2 * L₂bc(x̄, bc)
L = I * ρ - L_x
## solve the value function on the interior
v = L \ f.(x)
```
To extrapolate the interior solution to the boundary, one can call `extrapolatetoboundary` as follows:
```julia
v̄ = extrapolatetoboundary(x̄, v, bc) 
```
## Documentation
To install, run `] add SimpleDifferentialOperators` on Julia 1.3+.
For more usage information, see the docs badge above.
Detailed derivations and more applications can be found [here](https://github.com/QuantEcon/SimpleDifferentialOperators.jl/releases/download/dev/discretized-differential-operator-derivation.pdf).
## Troubleshooting
* As a reminder, the package requires **Julia 1.1 or later.**
* If you discover a bug in the code or math, please file an issue in this repo with the label "bug."
* The same holds for feature requests, with the appropriate label.