Differential Equations Day 5 -- Newton's Law of Cooling with Numerical Methods
Review of Euler's Method
As discussed on Day 4, Euler's Method is a numerical method for estimating solutions to differential equations with initial conditions. Euler's Method is as follows:
- Put the differential equation in slopefield form, . In practice, this means to solve the differential equation for dy/dx.
- Select a step count, n.
- Select a step size h (or sometimes also called dx or dt).
- The first estimate point is simply the initial condition, as a point in the plane, .
- Use the Euler's Method formulas to calculate the x and y coordinates of the next estimate point. See below for the Euler's Method formulas.
- Continue for n steps.
Overview of Newton's Law of Cooling
Newton's Law of Cooling (NLOC) is a widely used real-world application of first order ordinary differential equations. At its core, the NLOC is governed by the intuitive concept that that the temperature of an object will slowly get closer to the temperature of its surroundings. To quote an online lesson on the NLOC, in more technical language:
The temperature of a body changes at a rate proportional to the difference in temperature between the body and its surroundings
Let's put some mathematical notation on the objects mentioned in this sentence, and see how this is in fact a first order differential equation.
First, let's call
"the temperature of a body"
a function , the temperature of a body is T at time t. Therefore "The temperature of a body changes" would be or, if we drop the "(t)", .
Now let's look at the rest of the sentence, in particular this object:
"a rate proportional to the difference in temperature between the body and its surroundings."
Let's call the (constant) temperature of the surroundings . We use the subscript S for "surroundings". Then "the difference in temperature between the body and its surroundings" is . For the change in temperature of the body to be "proportional" to this difference means that is equal to a constant times . In other words
We'll discuss why there is a negative sign on k later in the example below. Note: It's customary to drop the "(t)" when referencing the function T, so you'll often see Newton's Law of Cooling stated as the following differential equation
An Example
A tub of ice cream is removed from the freezer at -18 degrees Celsius and brought into a room which is (positive) 32 degrees Celsius. The temperature of the ice cream, , measured in Celsius t minutes after being removed from the freezer is known to have a NLOC proportionality constant. Use Euler's Method with step size equal to 0.5 minutes to estimate the temperature of the ice cream after 2 minutes in the (positive) 32 degree air.
Solution
First, before we do any calculations, note that we should expect the ice cream to rise in temperature towards 32 degrees Celsius. NLOC will simply give us a way to dynamically model this exchange of heat. Euler's Method will give us a way to numerically engage with this model and discover what NLOC predicts the rise of the ice cream temperature to 32 degrees will look like..
Now, to get more specific, the NLOC model of the temperature of the ice cream is
The the initial condition on the temperature of the ice cream is .
Let's look at this setup in Geogebra. The slope field was generated with
slopefield(-ln(5/4)*(y-32))
and h was set to 0.5 as per the example. Note that without doing any calculations, we can see that the slope field will guide any solution towards 32 degrees Celsius whether the temperature is above or below 32 degrees. This is important to observe so that we can understand why there is a negative sign on k in NLOC. That negative sign is in front of k so that the flow of the slope field will be towards the temperature of the surroundings AND the constant can be positive. If the constant in front of was positive, then the slope field would flow away from the temperature of the surroundings which makes no sense (try it!).
To get started, use the pen tool (or just eyeball it) to make an estimate the temperature of the ice cream at t=2 minutes?
Now implement Euler's Method (described at the top of this page) out to t=2 minutes in steps of h=0.5 minutes.
Here are some tips:
The first estimate point is simply the initial condition, so we can get those points as follows
(note: case matters!):
x_1=x(InitialCondition)
y_1=y(InitialCondition)
For the second point, we will use the Euler's Method equations (see the top of this lesson) to get the next estimate point. In particular
x_2=x_1+h
y_2=y_1+(-ln(5/4)*(y_1-32))*h
Be sure to plot your coordinates as a point with the code (x_2,y_2)
Now continue more steps until you get to minute t=2. What does Euler's Method predict the temperature will be at t=2 minutes?
As you work, consider this question: do you think your application of Euler's Method is over estimating the temperature or underestimating the temperature (as compared to the actual curved solution function)? Look closely at the slope field and how it compares to the linear steps made by the Euler's Method estimate points.