QuantEcon / SimpleDifferentialOperators.jl

Library for simple upwind finite differences
MIT License
12 stars 2 forks source link

Notation cleanup in examples #120

Closed jlperla closed 5 years ago

jlperla commented 5 years ago

Looking at https://quantecon.github.io/SimpleDifferentialOperators.jl/dev/

For example,

# import SparseArrays package (for identity matrix and spzeros)
using SparseArrays

# differential operators on extended nodes
L̄ₓ = μ*L₁₋(x) + σ^2 / 2 * L₂(x)

# boundary conditions (i.e. B v̄ = b)
B = transpose([[-1; 1; zeros(M)] [zeros(M); -1; 1]])
b = [0.0; 0.0] 

# form bellman equation on extension
L̄ = [spzeros(M) ρ*I spzeros(M)] - L̄ₓ

# stack the systems of bellman and boundary conditions, and solve
v̄ =  [L̄; B] \ [f.(x); b]

# extract the interior (is identical with `v` above)
v =  v̄[2:end-1] 

should move to something like

# import SparseArrays package (for identity matrix and spzeros)
using SparseArrays

# differential operators on extended nodes
Lₓ = μ*L₁₋(x) + σ^2 / 2 * L₂(x)

# boundary conditions (i.e. B v̄ = b)
B = transpose([[-1; 1; zeros(M)] [zeros(M); -1; 1]])
b = [0.0; 0.0] 

# form bellman equation on extension
L = [spzeros(M) ρ*I spzeros(M)] - Lₓ

# stack the systems of bellman and boundary conditions, and solve
v̄ =  [L; B] \ [f.(x); b]

# extract the interior (is identical with `v` above)
v =  v̄[2:end-1] 

But there may be others.

jlperla commented 5 years ago

Note: my above suggestions are incorrect with the x vs. x_bar being passed to the operators. It should be x_bar instead (from slack discussion).

jlperla commented 5 years ago
chiyahn commented 5 years ago

Note that plots have to be updated as well since the implementation for $L_2$ has also changed