I have put together a very simple climate model based around four equations which define the state at time t
based on time t-1
, along with a initial state at time t = 0
. The problem arises when I wish to evaluate, say, the temperature at year 2000 (t = 2000
) or higher. I hit the recursion limit. I could keep increasing the $RecursionLimit
all the time, but I wonder if there is a better way to deal with the problem?
ClearAll[timeStep, waterDepth, gramsPerM3ofWater, joulesPerCalorie,
joulesToHeatWater, solarConstant, albedo, boltzmanConstant,
emissivity, temp, heatContent, incomingFlux, outgoingFlux, flux];
(*Constants*)
timeStep = 31536000;(*One year in seconds*)
waterDepth = 4000.;
gramsPerM3ofWater = 1000000.;
joulesPerCalorie = 4.186;
joulesToHeatWater = waterDepth*gramsPerM3ofWater*joulesPerCalorie;
solarConstant = 1350.;
albedo = 0.3;
incomingFlux = solarConstant (1 - albedo)/4;
boltzmanConstant = 5.67*^-8;
emissivity = 1.;
(*Initial State*)
temp[0] = 0.;
heatContent[0] = temp[0]*joulesToHeatWater;
outgoingFlux[0] = emissivity *boltzmanConstant*temp[0]^4;
flux[0] = (incomingFlux - outgoingFlux[0])*timeStep;
(*Equations*)
heatContent[t_] := heatContent[t - 1] + flux[t - 1]
temp[t_] := heatContent[t]/joulesToHeat
outgoingFlux[t_] := boltzmanConstant*temp[t]^4
flux[t_] := (incomingFlux - outgoingFlux[t])*timeStep