Math 132

Cooling, Heating, and Euler Finite Difference Models of Differential Equations

by S. R. Lubkin, based on material by R. White

Application

Consider a cup of hot tea in a cool room. The tea starts out hot but cools off. Now consider a glass of iced tea on a warm day. The iced tea will warm up. Both examples involve a change in temperature over time. In our previous examples of savings and loans, time behaved discretely - months were counted with integers, because the process involved things happening only once per month. But with heating and cooling, there are no big events (like a payment). Cooling and heating are happening continuously. So we need to study a dynamical system where time is continuous.

Mathematical Model

We will track the rate of change of temperature of the tea. What would it depend on? If we brainstorm, we generate a few ideas: There are so many factors we could include, but let's start simple, and declare in our word equation that
(rate of change of temp. of tea)  is proportional to (difference in temp. between tea and air)

Definitions

:= time (minutes)
y = y(t) := temperature of tea (degrees)
yr := temperature of room (assume it's constant) (degrees)
The phrase "is proportional to" means we will need a constant of proportionality. So one more definition is
K := temperature change coefficient (1/minutes)

Translation

Our word equation translates with these symbols to a differential equation
dy/dt = K*(y-yr)
since dy/dt can be defined as the rate of change of y with respect to t.
Note sometimes the derivative dy/dt is written as y'(t).

Before we go any further, we need to do a reality check. Does our differential equation model make sense? Let's try an example that we know.

It would be easier to just rewrite the differential equation as
dy/dt = -k*(y-yr)
and simply declare that
k := temperature change coefficient (1/minutes), must be > 0.
Let's do one more reality check: Finally, there is one more item we will need in our analysis. What temperature does the tea start at?
y0 := starting temperature of the tea (degrees)
So all together our model consists of a differential equation and its initial condition
dy/dt = -k*(y-yr)
y(0) = y0

Method of Solution

What does it mean to find a solution of a differential equation? The differential equation gives us a rate dy/dt as a function of y, but what we want to find is y as a function of t. We want to be able to predict what the temperature will be at some time, at any time, as long as we know what temperature we started with at time 0.

Once again, we have two methods of solution at our disposal: the analytical method and the approximate method.

Analytical Method

Maple is a very powerful program and it can do a lot of things. One of the nice things it can do is solve differential equations. Try the sample Maple session.
Maple gives us an exact solution
y(t) = yr + (y0 - yr)*exp(-k*t)
(Recall that exp(x) is the same as e^x or ex.)

You will notice that if we start the tea at 50 degrees in a room at 72 degrees, the temperature rises smoothly and levels off at 72 degrees. This is what we expect. Try a starting temperature which is hotter than the room temperature. What does the solution curve look like?

Approximate Method

Suppose Maple couldn't solve the differential equation for us. For many differential equations this is true! We could still find a numerical approximation to the correct answer by Euler's Method. The basic idea is that instead of thinking of time as continuous, we think of time as discrete (as we did in the previous two lessons). We could break up hours into minutes, or 10-minute intervals, or in fact any length interval. Think of checking the temperature every 5 minutes, or every 10 minutes, etc. Then define
D := time interval
n := how many time intervals since t = 0
Note that t = nD, as long as t is some multiple of the measuring interval D. Then we write the discrete version of y(t),
yn := temperature at discrete time time n
The derivative dy/dt can be approximated by the difference
dy/dt ~ (yn+1 - yn)/D.
Now we can translate our differential equation model
dy/dt = -k*(y-yr)
into a difference equation model
(yn+1 - yn)/D = -k*(yn-yr)
or
yn+1 =  yn -D*k*(yn-yr)
or, collecting terms,
yn+1 =  (1-D*k)*yn + D*k*yr
We can solve this difference equation in Excel by the iterative method or we can take advantage of the fact that our approximation above is of the form
yn+1 =  a*yn + b
to use the formula from the theorem of the previous two lessons.

Implementation

Open a spreadsheet. In column A we will make a series for time, in intervals equal to D. In column B we will use the iterative method to find yt at each t. In column C we will find the exact solution (analytical method). In column D we will compare the results from B and C. Elsewhere in the spreadsheet we will have a parameter table, so we can easily keep track of the numbers in our work. Finally, we will make a chart comparing the iterative and analytical methods.

The spreadsheet should be entered like this:
A B C D E F G H
1 t yt (iterative) y(t) (exact) % error Parameters
2 0 =$g$3 =$g$3 =(b2-c2)/b2 D k y0 yr
3 =A2+$E$3 =(1-$E$3*$F$3)*B2+$E$3*$F$3*$H$3 =$H$3+($G$3-$H$3)*EXP(-$F$3*A3) 5 0.12 50 72
4
5
Copy the formulas down in the columns A through D. Finally, make a scatterplot of columns A through C so we can see whether the approximate method is close or not to the exact solution. The resulting spreadsheet should look like this.

Comparison

How large is the error of the approximate solution? You can see it in column D and also in the chart. Finally, try a different D, first a smaller D, then a larger D. How does D affect the error?

Discussion

It clearly isn't necessary to use an approximate method for a differential equation when we know the exact solution. But there are a lot of differential equations where we don't know the exact solution, and then we need to use numerical approximations like Euler's method.