QuantEcon / SimpleDifferentialOperators.jl

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

Formula or implementation for $L_2$ on irregular grids is most likely wrong #126

Closed chiyahn closed 5 years ago

chiyahn commented 5 years ago

Relates to #114

There are two evidences:

Once #114 is done,

chiyahn commented 5 years ago

It turns out that there was a mistake in L_2, not on L_2^B; note that all the evidence I provided are based on the discrepancy between L_2 and L_2^B solutions. In fact, I found that the unit tests still all pass for L_2^B. Will make a fix rn

chiyahn commented 5 years ago

Here's what makes it different: We had been using

L_2[1,1] = -1 / Δ_1
L_2[end,end] = -1/Δ_M

where Δ_1 and Δ_M are x̄[2] - x̄[1] and x̄[end] - x̄[end-1] respectively. The correct implementation should be

L_2[1,1] = - 1 / (Δ_1m*(Δ_1m+Δ_1p))
L_2[end,end] = -1 / (Δ_Mp*(Δ_Mm+Δ_Mp))

where

    Δ_1m = x̄[2] - x̄[1]
    Δ_1p = x̄[3] - x̄[2]
    Δ_Mm = x̄[end-1] - x̄[end-2]
    Δ_Mp = x̄[end] - x̄[end-1]

(Fixed at https://github.com/QuantEcon/SimpleDifferentialOperators.jl/commit/dd118a47676daf430d9554a1beaa6ebce5c34fb0)