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 t.

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

function nextTemp(prevTemp):
    cooling = prevTemp * COOLING_RATIO
    newTemp = prevTemp - cooling + HEATING
    return newTemp

function printVals(): 
    print "t= %2d   T= %5.2f" % (time, temp)

time = 0
for i in range(15):
    temp = nextTemp(temp)
    time += 1

This produces

    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
  • $\begingroup$ No, sorry, I can hardly remember what a differential equation is, and I certainly don't know how to use it here. $\endgroup$ Sep 2, 2015 at 13:44
  • $\begingroup$ In physics, it makes sense to be continuous. But your pseudocode is cleary discrete. If is continuous, can be easily solved with calculus. A solution using calculus will help you? If discrete, can be solved using geometrical sequences. $\endgroup$ Sep 2, 2015 at 13:44
  • $\begingroup$ I think, if your problem is the discrete version, then math SE is more suited for this question. I also think, even the continuous version would be more suited in math SE. $\endgroup$ Sep 2, 2015 at 14:27

1 Answer 1


I'll assume this problem is continuous as it makes sense on physics, and not discrete as you wrote on your pseudocode. Its worth pointing out, it makes a huge difference if the problem is discrete or continuous, as I have explained in the comments. However, one can also write a pseudocode for the continuous problem as well:

HEATING = 1 # degree per minute
COOLING_RATIO = 0.2 # 20% per minute

function nextTemp(prevTemp, timeElapsed):
    cooling = prevTemp * COOLING_RATIO * timeElapsed
    heating = HEATING * timeElapsed
    newTemp = prevTemp - cooling + heating
    return newTemp

function printVals(): 
    print "t= %2d   T= %5.2f" % (time, temp)

time = 0
dt = 0.00001;   # The smaller the better.
for i=0 until i=15
    temp = nextTemp(temp, dt)
    i += dt
    time += dt
    if (isInteger(time)) printVals()    # e.g.: If time=1.0000, then printVals()

Well, it is likely you seems not to know calculus, so, I'll "solve" without it. According to what you said: Each minute, it raises 1 degree, and it decreases the temperature of the body. So, the rate of increase of temperature: $$ \frac{\Delta T}{\Delta t} = 1 - T $$

We have to compute this in the tiniest possible $\Delta t$. Mathematically, we say that $\Delta t$ is so small that it approach zero: $\Delta t \to 0$. In that case, it becomes a differential and I can write $dt$. A tiniest difference in time will mean a tiniest difference in temperature $dT$. Thus: $$ \frac{dT}{dt} = 1 - T $$

We identify a differential equation of first order. We sick a function $T(t)$ dependent on time, such that its derivative is equal to $1-T(t)$. The derivative of the function (the left part) can also be written in this notation: $T'(t)$. With a prime on it. Our equation then: $$ T'(t) = 1 - T(t), \quad\mbox{ for }\quad T(0) = 20 $$

Now we copy paste it on wolframalpha.com, and got a solution: $$ T(t) = 10\left(1 + e^{-0.1t}\right) $$

Note that, in the continuous solution, as t gets larger and larger, that is, as $t\to\infty$, then $T(t) = 10$. So, the temperature of the body will estabilize at 10 degree. Also, notice that in the solution to the continuous problem, $T$ is very different from your solution (the discrete problem).

   t=0,   20.000
   t=1,   19.048
   t=2,   18.187
   t=3,   17.408
   t=4,   16.703
   t=5,   16.065
   t=6,   15.488
   t=7,   14.966
   t=8,   14.493
   t=9,   14.066
   t=10,  13.679
   t=11,  13.329
   t=12,  13.012
   t=13,  12.725
   t=14,  12.466
   t=15,  12.231
  • $\begingroup$ Now I understand what you meant by continuous/discrete. Yes the problem is discrete. I just solved it by Python, and then supplied the results (and the code) to make sure the readers understood. $\endgroup$ Sep 2, 2015 at 14:45
  • $\begingroup$ I understand the formula, obviously. And I need a litte time to understand how you got there. But thank you so much :) $\endgroup$ Sep 2, 2015 at 14:46
  • $\begingroup$ @MadsSkjern No problem :). And since you want discrete, its very simple to solve: All you have to do is solve the recursive sequence $T_{n+1} = (T_n+1) - 0.1T_n$, where $n$ is the minutes. If you wish, you can ask on Math SE. I may even answer it =). $\endgroup$ Sep 2, 2015 at 14:53
  • $\begingroup$ Oh no! I wanted to write "The problem is continuous"! Anyway, I'm happy to have the discrete solution too :) $\endgroup$ Sep 2, 2015 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.