60
Canonical Grid model
Economics - Solow accuracy comparison
Compare two solver tolerances against the closed-form path on identical output times.
- Scale
- Small
- Source
- economics-growth-convergence.grid
- Length
- 39 lines
- Collection
- Advanced language
- Level
- Intermediate
- Runtime
- Portable
- Version
- 1.0.0
MODEL "Economics - Solow accuracy comparison"
DESCRIPTION "Compare two solver tolerances against the closed-form path on identical output times."
VERSION "1.0.0"
AUTHOR "Grid"
TAGS "economics", "accuracy", "ode"
input SavingRate = 0.25
VALIDATE BETWEEN 0.01 AND 0.9 MESSAGE "Choose a saving fraction between 0.01 and 0.9."
Depreciation = 0.05
CapitalShare = 1 / 3
InitialCapital = 1
Horizon = 100
OutputCount = 51
DEFINE ClosedCapital(time) = (SavingRate / Depreciation + (InitialCapital^(1 - CapitalShare) - SavingRate / Depreciation) * EXP(-(1 - CapitalShare) * Depreciation * time))^(1 / (1 - CapitalShare))
output StandardPath = ODE_SOLVE((time, capital) => SavingRate * capital^CapitalShare - Depreciation * capital, InitialCapital, 0, Horizon, OutputCount, 1e-6, 1e-8, 10000, "rk45")
output TighterPath = ODE_SOLVE((time, capital) => SavingRate * capital^CapitalShare - Depreciation * capital, InitialCapital, 0, Horizon, OutputCount, 1e-10, 1e-12, 10000, "rk45")
output StandardMaxError = MAX(MAP(SEQUENCE(1, OutputCount), (position) => ABS(INDEX(StandardPath, position, 2) - ClosedCapital(INDEX(StandardPath, position, 1)))))
output TighterMaxError = MAX(MAP(SEQUENCE(1, OutputCount), (position) => ABS(INDEX(TighterPath, position, 2) - ClosedCapital(INDEX(TighterPath, position, 1)))))
output StandardFinal = INDEX(StandardPath, OutputCount, 2)
output TighterFinal = INDEX(TighterPath, OutputCount, 2)
output AnalyticFinal = ClosedCapital(Horizon)
output SteadyCapital = (SavingRate / Depreciation)^(1 / (1 - CapitalShare))
output AccuracyInterpretation = "Tolerances control estimated local error, not a guaranteed global error bound. Compare the entire path at the same output times. More output rows do not by themselves tighten the solver's internal error control. The steady state is an infinite-horizon limit, not the exact finite-horizon endpoint."
A1 = "Solow accuracy"
B3 = "Standard"
C3 = "Tighter"
A4 = "Max error"
B4 = StandardMaxError
C4 = TighterMaxError
A5 = "At year 100"
B5 = StandardFinal
C5 = TighterFinal
A6 = "Exact endpoint"
B6 = AnalyticFinal
A7 = "Steady state"
B7 = SteadyCapital
END MODEL