UCES
Course: Methods and Analysis in UCES
Model: Newton's law of cooling
Assessment: discrete error, accumulation errors
Prerequisites:
Objectives:
General Information: This is the first of a series of continuum models for heat transfer. We will illustrate model evolution and the approximation of continuum models by discrete models.
Contact Person: R. E. White, NCSU, white@math.ncsu.edu
Revision Date: 8-2-94
Copyright ©1994, R. E. White. All rights reserved.
Initial value problems have the form
| ut = f(t,u) and u(0) given. | (1) |
The simplest cases can be solved by separation of variable, but in general they
do not have to have closed form solutions; for example, let
Consider a well stirred liquid such as a cup of coffee. We will assume that the temperature is uniform with respect to space, but the temperature may be changing with respect to time. We wish to predict the temperature as a function of time given some initial observations about the temperature. For example, a cup of coffee will cool much faster in a metal cup than in an insulated cup. Or, the coffee will cool much faster if the surrounding temperature is very cold.
Newton's empirical law of cooling states that the rate of change of the temperature is proportional to the difference in the surrounding temperature and the temperature of the liquid. This is a continuum version of the one described in the first section on floating point numbers. In fact, the Euler algorithm for the following differential equation is exactly the discrete version!
The closed form solution of this differential equation can be found by the separation of variables method and is
If the c is not given, then it can be found from a second observation
The first method involves the approximation of ut by the finite difference
where h = T/K, uk is an approximation of u(kh) and f is evaluated at
| (uk+1 - uk)/h = f(kh,uk). | (2) |
The second choice is the simplest because it does not require the solution of a possibly nonlinear problem at each time step. The scheme given by (2) is called Euler's method.
Let u(k) be an array of dimension K+1 with u(0) equal to the initial temperature.
u(k) will be the approximate values of the temperature at time equal to kh ,
that is,
Euler's Algorithm.
Example. Let f(t,u) = t2 + u2 and u(0) = 0.
Suppose we let h = .1 and wish to approximate u(1). Then we must compute
u10 by repeating the calculation in the loop 10 times. So,
What is the appropriate choice for h?
Use Newton's law of cooling to predict the temperature of a cup of coffee.
The coffee is kept well stirred by walking around the classroom. Also, we
need to know when its temperature reaches 110, after that the professor gets
irritable. Today the initial temperate was 200 and five minutes later it was
observed to be 190. The second measurement varies with the type of coffee
container. The continuum model is
It is possible to solve this model in closed form, and the solution is
The c is determined from the second observation and is c = (-1/5)ln(12/13) =
.01600854
The discrete model is formed by using Euler's algorithm and is
The c must be determined from the second observation. Here the increase of
time from 0 to 5 is not too large, and so we may approximate the
ut (0) by (190 - 200)/5 and now put this into the differential
equation
We will choose the last possible right side so that c = 2/123.5 = .01619433
which is not too far from the c in the continuum model. For K =10 the time
step is h = 50/10, and hc = .08097. At the end of the class the coffee's
computed temperature was 127, yeah.
The computations below use a larger c = .061 and indicate the effect of the
mesh size on the numerical solution. For this example the numerical solution
appears to converge as K increases from 4 to 8 and to 16. The graphs of the
numerical solution are in increasing order.
Maple Code for a Well Stirred Liquid.
h = T/K
u(0) = u0
for k = 0, K-1
u(k+1) = u(k) + h*f(k*h,u(k))
endloop.
u0 = 200
usur = 70
T = 50
h = 50/K.
The Procedure is Defined:
> EULER:=proc(f,t0,u0,T,K)
> t(0):= t0:
> h:=T/K:
> u(0):= u0:
> for k from 0 to K do
> u(k+1):= u(k) + h*f(t(k),u(k)):
> t(k+1):= t(k) + h:
> od:
> end:
Input Data:
> t:='t':
> u:='u':
> f:=(t,u)->.061*(70 - u);
> t0:=0:
> u0:=200:
> T:=50:
> K:=10:
The Procedure is Called for Different Mesh h = T/K:
> with(plots):
Use K = 4.
> EULER(f,0,200,50,4):
> L:=[seq([t(n),u(n)],n=0..4)]:
Use K = 8.
> EULER(f,0,200,50,8);
> LL:=[seq([t(n),u(n)],n=0..8)]:
Use K = 16.
> EULER(f,0,200,50,16);
> LLL:=[seq([t(n),u(n)],n=0..16)]:
The Output is Graphed for the Three Mesh Choices:
> plot({L,LL,LLL},x=0..50);
![]() |
| Figure: Convergence of Numerical Solution |
The next numerical experiments are done using Matlab. They illustrate numerical error as a function of the number of steps. This is done with the equation for Newton's law of cooling with usur = 70 and c = 1.0; the error is computed for time equal to 1.0.
Matlab Code for Euler's Algorithm.
clear; i=0; vec = zeros(12,1); vecdt= zeros(12,1); for kk=4:4:48 T =1.0; dt =T/kk; u0 = 200.; c = 1.0; usur = 70.; uk = u0; for k = 1:kk uk = uk +dt*c*(usur -uk); uex = usur + (u0 -usur)*exp(-c*k*dt); error = abs(uk - uex); end i= i+1; vec(i) = error; vecdt(i) = 1/dt; end plot(vecdt,vec)
![]() |
| Figure: Error versus Steps (h = T/steps) |
If the liquid is not well stirred, then the temperature will vary within the container. This results in diffusion of heat from a warm region to a cool region. The above model does not take this into consideration. Also, in our analysis the surrounding temperature was held constant. Variable surrounding temperature can easily be accounted for in our present model.
Clearly this is a very inexpensive algorithm to execute. However, there are sizable errors. There are two types of errors: the discretization and accumulation errors.
The overall error contains both errors and is Edk + Erk = Uk - u(kh). We will describe these errors for a specific example, but a more general analysis follows from the subsequent analysis.
Now we will give the discretization error analysis. The relevant terms for the error analysis are
| ut (kh) = c(usur - u(kh)), | (3) |
| uk+1 = uk + hc(usur - uk ) and | (4) |
| Uk+1 = Uk + hc(usur - Uk ) + Rk+1 | (5) |
Use the extended mean value theorem along with (3), and also use (4).
| Edk+1 = | uk+1 - u((k+1)h) |
| = | [uk + hc(usur - uk )] - [u(kh) + c(usur - u(kh))h + utt (ck+1 )h2 /2] |
| = | a Edk + bk+1 h2 /2 where a = 1 - ch and bk+1 = -utt (ck+1 ). |
Let |a| = 1 + ch = r and |bk+1 | < M2 = M. Use an analysis similar to that used for the first order difference algorithm
| |Edk+1 | < | r |Edk | + Mh2 /2 | |
| < | rK|Ed0 | + (rK - 1)/(r - 1) Mh2 /2. | (6) |
Assume Ed0 = 0 and the fact that r = 1 + ch with h = T/K to obtain
Also recall that as x increases (1 + a/x)x converges to ea from below, and so we have
Thus,
| |Edk+1 | < [(ecT - 1)M/(2c)]h. | (7) |
An analysis of the accumulation error is similar, and these are summarized the
following theorem which is stated for the more general problem
Euler Error Theorem. Consider Euler's algorithm for the general initial
value problem. Assume the initial value problem has a solution which has two
continuous derivatives on [0,T]. Let
f:[0,T]×(-
,
)
R
be continuous and fu , the derivative of f with respect to the
second variable, satisfies
.
If Ed0 =
Er0 = 0,
h = T/K, max | utt | < M for t in [0,T], and
Corollary. If R < Rh2 , then the overall error is of order h, that is,
The above accumulation error approximations suggest that if one fixed T and let K increase (h decreases), then the accumulation error would continue to grow. However, if one also increased the precision (R decreases) in a suitable way, then the overall error will also be bounded by a constant times h.
In the following table we list the discretization errors for the above first order Euler algorithm, and the second order Euler-Trapezoid algorithm which we will describe in the next section. The tabulated errors were the largest values of all the points in time. The constant c was from the discrete model.
| K | Euler Error | (Euler Error)/h | ETrap. Err. | (ETrap. Err.)/h2 |
| 10 | 1.9710 | .3942 | .025600 | .001 |
| 20 | 0.9664 | .3866 | .006400 | .001 |
| 40 | 0.4786 | .3829 | .001600 | .001 |
| 80 | 0.2382 | .3811 | .000399 | .001 |
| 160 | 0.1188 | .3802 | .000010 | .001 |