PYTHON
Newton's (inaccurate!) law of cooling says that the temperature of an object changes at a rate proportional to the difference between its temperature and that of the surrounding medium (the ambient temperature). So the change in temperature of an object with respect to time can be written as:
dT/dt = -k(T - Ta)
where:
T = the temperature of the object
t = elapsed time
k = the proportionality constant (an empirical value derived from
the liquid and cup properties)
Ta = the ambient temperature
Use this relationship to numerically estimate (using python) the temperature of my cup of coffee cooling over time while sitting on my desk. Use the following parameter values:
If coffee must be 35∘∘ C or below for me to drink it without burning my mouth, how long do I have to wait until I can safely drink it?
Plot the coffee temperature over that duration.
The graph for Temperature vs Time is given below. From the analysis of the graph, it requires 12 iterations(12minutes), so that the Temperature of Coffee becomes less than equal to 35C. The python code used for producing the graph is also added below.
Python Code:
import matplotlib.pyplot as plt
time=[]
value=[]
ta=21
tcur=68
dt=1
k=0.1
while 1==1:
time.append(i)
inter=2.0*tcur-k*tcur*dt+2*k*ta*dt
inter=(inter)/(2+k*dt)
value.append(inter)
tcur=inter
i+=1
if inter<32:
break
plt.show(time,value)
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.show()
Get Answers For Free
Most questions answered within 1 hours.