You are on page 1of 7

Lab 9 - Differential Equations

dc
dt = kc
a+c k = binding rate = 1 a = 21 k = 0.5

Setup

In preparation for Thanksgiving, Carter places his turkey roast in the oven and lets it bake until
it reaches a temperature of 400 degrees Fahrenheit and then takes it out to cool. Unfortunately,
he immediately forgets about it and lets it cool for too long. In this problem, we’ll model the
temperature of the turkey and try to figure out if it will be too cold for Carter to eat during his
Thanksgiving Zoom meeting.
After the turkey is removed from the oven and placed onto the kitchen counter, it starts to cool
down. The temPerature of the turkey (which we’ll call P, since t is already taken by “time”) obeys
Newton’s Law of Cooling,

dP
= α(A − P )
dt
where A is the ambient temperature in the kitchen. Gas prices are absurd, so Carter maintains an
ambient temperature of A = 50 degrees Fahrenheit. The parameter α > 0 dictates the speed at
which the turkey cools down. Let’s use α = 0.1.

Question 1

As with most differential equations in the class, an initial condition is necessary. Somewhere in the
Setup above I’ve provided you with an initial condition, P (0), but didn’t explicitly say what it is.
What is P (0)?
P (0)=400 degrees Fahrenheit

Question 2

Before solving the differential equation, think about this: is dP


dt positive or negative, and what does
that mean? In other words, is P > A, or is P < A? Why does one make sense and not the other?
dP
dt is negative because P > A (400 > 50 degrees)

1
Question 3

Let’s pretend that Carter had suffered a nasty bout of sleepwalking the night before and removed
the turkey from the freezer, placing it onto the kitchen counter without first cooking it in the oven.
It turns out that the equation for Newton’s Law of Cooling would still apply to the temperature
of the turkey, except in this case it might be more appropriate to call it Newton’s Law of Heating.
In this situation, would dP
dt be positive or negative, and why?
dP
dt is positive this time because P < A, the turkey is heating up to room temperature this time
instead of cooling down.

Question 4

Solve the differential equation with the initial condition from Question 1 and separation of variables.
P (t) = 50 + 350(exp(−αt))

Question 5

Say Carter goes to take a quick nap but ends up falling asleep for a very long time. What happens
to the temperature of the turkey as t → ∞ ? Why does this make sense? Make a plot of the
function that demonstrates this behavior.
The temperature of the turkey, whether it starts above or below 50 degrees, will approach 50 as
t→∞

alpha <- 0.1


A <- 50

P <- function(t) 50 + 350*exp(-alpha*t)


plot(P, ylim=c(50,400), xlim=c(0,120), ylab='Temperature', xlab='Time', main='Turkey Temperatur

2
Turkey Temperature
150 250 350
Temperature

50

0 20 40 60 80 100 120

Time

Euler’s Method

Although we obtained a solution to the differential equation in the previous section, there are many
problems for which this simply cannot be done by hand. One way of obtaining approximate answers
on the computer is to use Euler’s method.
Suppose we have some differential equation

dP
= f (P ), P (0) = P0 .
dt
We can use a tangent line approximation to the true solution P (t) in order to approximate the
value at some time which is close to our initial point. If our timesteps are of size ∆t, then the first
point we approximate would be

d
P (∆t) ≈ P (0) + ∆t P (0),
dt
= P0 + ∆tf (P0 ).

Then we can repeat this procedure to get P (2∆t):

d
P (2∆t) ≈ P (∆t) + ∆t P (∆t),
dt
= (P0 + ∆tf (P0 )) + ∆tf (P0 + ∆tf (P0 ).

Then we would use the answer we get for P (2∆t) to help us solve P (3∆t), et cetera. Luckily we
can code up a for loop to do this for us rapidly.

3
Question 6

Complete the code below show the (approximate) solution obtained from Euler’s method. Use
a timestep of ∆t = 5 minutes and run the simulation until t = 30 minutes. How good of an
approximation is this?

#Euler's method!

#Enter in time domain and n to find dt. FILL IN THIS SECTION


t0 <- 0 # initial time
tmax <- 30 # end time
P0 <- 400 # initial temp
dt <- 5 # time step delta t
n <- tmax/dt #count of iterations
A <- 50 # ambient temperature

#This section creates lists to store our time points, t, and P values.
t <- seq(1,n)
P <- seq(1,n)

#Set up initial conditions.


t[1] <- t0;
P[1] <- P0;

#Create function for our differential equation. FILL IN THIS SECTION


dPdt = function(P){ 0.1*(A-P)}

#Loops through n times to find the time points and tangent line approximations for each of the
for(i in 2:(n+1)){
t[i] <- t[i-1] + dt; # - updates the current time at step i
P[i] <- P[i-1] + dPdt(P[i-1])*dt; # - updates P values at step i
}

####### Ploting Part of the code (no need to change) ##################


truesolfunc = function(t){350*exp(-t*.1)+50}
tfine = seq(t0,tmax,.1);
truesol = truesolfunc(tfine)

plot(t,P,type='b',ann='false',lwd=3)
lines(tfine,truesol,col='red',lwd='2',lty=2)
title(main='Turkey temperature',ylab='P (degrees F)',xlab='time (minutes)')
legend(15,350, c('Eulers','true'), col=c('black','red'), lwd=c(2,2), lty=c(1,2))

4
Turkey temperature
350
P (degrees F)

Eulers
250

true
150
50

0 5 10 15 20 25 30

time (minutes)

Question 7

Try a smaller value of ∆t of your choice. Does the approximation get better or worse? Why?
The approximation gets better because the interval gets smaller, and therefore more accurate.

#Euler's method!

#Enter in time domain and n to find dt. FILL IN THIS SECTION


t0 <- 0 # initial time
tmax <- 30 # end time
P0 <- 400 # initial temp
dt <- 1 # time step delta t
n <- tmax/dt #count of iterations
A <- 50 # ambient temperature

#This section creates lists to store our time points, t, and P values.
t <- seq(1,n)
P <- seq(1,n)

#Set up initial conditions.


t[1] <- t0;
P[1] <- P0;

#Create function for our differential equation. FILL IN THIS SECTION


dPdt = function(P){ 0.1*(A-P)}

5
#Loops through n times to find the time points and tangent line approximations for each of the
for(i in 2:(n+1)){
t[i] <- t[i-1] + dt; # - updates the current time at step i
P[i] <- P[i-1] + dPdt(P[i-1])*dt; # - updates P values at step i
}

####### Ploting Part of the code (no need to change) ##################


truesolfunc = function(t){350*exp(-t*.1)+50}
tfine = seq(t0,tmax,.1);
truesol = truesolfunc(tfine)

plot(t,P,type='b',ann='false',lwd=3)
lines(tfine,truesol,col='red',lwd='2',lty=2)
title(main='Turkey temperature',ylab='P (degrees F)',xlab='time (minutes)')
legend(15,350, c('Eulers','true'), col=c('black','red'), lwd=c(2,2), lty=c(1,2))

Turkey temperature
400
P (degrees F)

300

Eulers
true
200
100

0 5 10 15 20 25 30

time (minutes)

Murder mystery

Question 8

Detective Amy Santiago is called to the scene of a crime where a body has just been found. She
arrives on the scene at 10:23 pm and begins her investigation. She immediately measures the
temperature of the body and determines it to be 80◦F. She checks the smart thermostat and finds
that the room has been kept at a constant 68 degrees Fahrenheit for the past 3 days. Use Newton’s

6
law of cooling to derive a model for the temperature H(t) of the corpse. We will determine the
cooling constant α later.
H(t) = 68 + (H0 − 68)exp(−αt) H0 = 80 so 80 − 68 = 12

Question 9

After collecting some evidence from the crime scene for one hour, she measures the temperature of
the body again and it is 78.5 degrees Fahrenheit. Assuming that the victim’s body temperature
was 98.6 degrees Fahrenheit just prior to death, find the cooling constant α.
α = 0.1335

Question 10

Detective Santiago checks the building’s security cameras and sees that (1) a take-out delivery driver
delivered lunch to the victim that day at 2:30 pm, (2) a door-to-door phone book salesperson showed
up at 3:20 pm, (3) and a package was delivered at their doorstep at 4:15 pm. The victim never
left their apartment that day and no other people came to their door. Who is the prime murder
suspect? Explain your answer. (The problem to solve is this: Figure out how long it would take
for the body to cool from 98.6 degrees (at time of death) to 80◦F (at 10:23 pm). Then you will
know what time the murder occurred.)
The phone book sales person should be the prime murder suspect because it took about 7 hours
for the body to cool from 98.6 to 80 degrees.

Submissions

To submit, provide answers to all of the problems. Knit this code into a PDF file and upload it to
Canvas. If you generate plots, make sure they appear in the knitted pdf. The suggested due date
is Monday by 11:59PM, but if you aren’t finished you can hold off submitting your document until
you feel it’s ready. Labs are graded on a “Good job!” or “Not yet” scale, with as many re-tries as
you need.

You might also like