From 842d341bda4cc58eea8598b61d6afa26cf6272cd Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 20 Jun 2024 10:44:16 -0400 Subject: [PATCH] Update WangWangYang.jl --- examples/ConsumptionProblem/WangWangYang.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/ConsumptionProblem/WangWangYang.jl b/examples/ConsumptionProblem/WangWangYang.jl index 9c972ee..057c566 100644 --- a/examples/ConsumptionProblem/WangWangYang.jl +++ b/examples/ConsumptionProblem/WangWangYang.jl @@ -39,19 +39,20 @@ function (m::WangWangYangModel)(state::NamedTuple, y::NamedTuple) end m = WangWangYangModel() -stategrid = OrderedDict(:w => range(m.wmin^(1/2), m.wmax^(1/2), length = 100).^2) +stategrid = OrderedDict(:w => range(m.wmin^(1/2), m.wmax^(1/2), length = 1000).^2) yend = OrderedDict(:p => 1 .+ stategrid[:w]) -result = pdesolve(m, stategrid, yend, bc = OrderedDict(:pw => (1.0, 1.0))) +@time result = pdesolve(m, stategrid, yend, bc = OrderedDict(:pw => (1.0, 1.0))) @assert result.residual_norm <= 1e-5 # Alternative solution bypassing pdesolve # just encode the PDE has a vector equation using InfinitesimalGenerators + function solve!(pts, m, ws, ps) (; μ, σ, r, ρ, γ, ψ, wmin, wmax) = m - pw_ups = FirstDerivative(ws, ps; direction = :upward, bc = (0.0, 1.0)) - pw_downs = FirstDerivative(ws, ps; direction = :downward, bc = (0.0, 1.0)) + pw_ups = FirstDerivative(ws, ps; direction = :forward, bc = (0.0, 1.0)) + pw_downs = FirstDerivative(ws, ps; direction = :backward, bc = (0.0, 1.0)) pwws = SecondDerivative(ws, ps, bc = (0.0, 1.0)) for i in eachindex(ws) w = ws[i] @@ -79,6 +80,6 @@ function solve!(pts, m, ws, ps) end m = WangWangYangModel() -ws = range(m.wmin^(1/2), m.wmax^(1/2), length = 100).^2 +ws = range(m.wmin^(1/2), m.wmax^(1/2), length = 1000).^2 ps = 1 .+ stategrid[:w] -finiteschemesolve((ydot, y) -> solve!(ydot, m, ws, y), ps) \ No newline at end of file +@time finiteschemesolve((ydot, y) -> solve!(ydot, m, ws, y), ps) \ No newline at end of file