This is almost more of a math question, and a simple one, but I can't figure it out, and I haven't been able to find a solution online since I don't really know what words to search for.
There is a body of some temperature, the starting temperature is 20deg, and it is both cooling to the surroundings (power is proportional to delta T) and being heated by an electric heating element with a constant power.
How need a function that describes the temperature at some time
I have abstracted things like mass, heat capacity, power, etc away in the example.
- heating: adds 1 degree per minute
- cooling: subtracts 10% of the difference in temperature between the element and the surroundings (always at 0deg). Since the surrounding temperature is 0deg, the delta temperature is the same as the temperature of the body.
In case the above can be misunderstood (my physics or math language is very limited) I have written a piece of pseudo code below that shows the development (is that the right word) over time:
HEATING = 1 # degree per minute COOLING_RATIO = 0.2 # 20% per minute START_TEMP = 20 function nextTemp(prevTemp): cooling = prevTemp * COOLING_RATIO newTemp = prevTemp - cooling + HEATING return newTemp function printVals(): print "t= %2d T= %5.2f" % (time, temp) temp = START_TEMP time = 0 printVals() for i in range(15): temp = nextTemp(temp) time += 1 printVals()
t= 0 T= 20.00 t= 1 T= 17.00 t= 2 T= 14.60 t= 3 T= 12.68 t= 4 T= 11.14 t= 5 T= 9.92 t= 6 T= 8.93 t= 7 T= 8.15 t= 8 T= 7.52 t= 9 T= 7.01 t= 10 T= 6.61 t= 11 T= 6.29 t= 12 T= 6.03 t= 13 T= 5.82 t= 14 T= 5.66 t= 15 T= 5.53