Project Two James K. Peterson Department of Biological Sciences and Department of Mathematical Sciences Clemson University March 27, 2018 Outline Cooling Models Estimating the Cooling Rate k Typical Cooling Project Matlab Session
Newton formulated a law of cooling by observing how the temperature of a hot object cooled. As you might expect, this is called Newton s Law Of Cooling. If we let T (t) represent the temperature of the liquid in some container and A denote the ambient temperature of the air around the container, then Newton observed that T (t) (T (t) A). We will assume that the temperature outside the container, A, is smaller than the initial temperature of the hot liquid inside. So we expect the temperature of the liquid to go down with time. Let the constant of proportionality be k. Next, we solve T (t) = k (T (t) A), T (0) = T0 where T0 is the initial temperature of the liquid. For example, we might want to solve T (t) = k(t (t) 70), T (0) = 210 where all of our temperatures are measured in degrees Fahrenheit. We use our usual solution methods to solve this. Divide both sides dt by T 70 to get T 70 = k dt. Then integrate both sides to get ln T (t) 70 = kt + C. Then, exponentiate: T (t) 70 = Be kt. Now, since we start at 210 degrees and the ambient temperature is 70 degrees, we know the temperature of our liquid will go down with time. Thus, we have T (t) 70 = Be kt.
Solving, we find T (t) = 70 + Be kt. Since the initial condition is T (0) = 210, we find T (0) = 210 = 70 + Be 0 = 70 + B, and so B = 140. Putting all of this together, we see the solution to the model is T (t) = 70 + 140e kt. Now since the temperature of our liquid is going down, it is apparent that the proportionality constant k must be negative. In fact, our common sense tells us that as time increases, the temperature of the liquid approaches the ambient temperature 70 asymptotically from above. Example Solve T (t) = k(t (t) 70) with T (0) = 210 and then use the conditions T (10) = 140 to find k. Here time is measured in minutes. Solution First, we solve as usual to find T (t) = 70 + 140e kt. Next, we know T (10) = 140, so we must have T (10) = 140 = 70 + 140e 10k. Thus 70 = 140e 10k 1 2 = e10k ln(2) = 10k. and so k = ln(2)/10 =.0693.
We now know the general cooling model is which has solution T (t) = k(t (t) A), T (0) = T 0. T (t) = A + Be kt. Applying the initial condition, we get T 0 = A + B. or B = T 0 A. Hence, the solution is T (t) = A + (T 0 A)e kt. The one parameter we don t know is the constant of proportionality, k. However, let s assume we have collected some data in the form {t i, T i} for 1 i N for some finite integer N. Rewrite the solution as T (t) A T 0 A = e kt. Now take the logarithm of both sides to get ( ) T (t) A ln = kt. (1) T 0 A This tell us how to estimate the value of k. Let the variable U(t) be defined to be ( ) T (t) A U(t) = ln T 0 A Then, Equation 1 can be written as U(t) = kt. Thus, the variable U is linear in t; i.e. if we graph U versus t we should see a straight line with slope k.
Our collected data consists of pairs of the form (time, temperature). Suppose we collected N such pairs. Label them as (t i, T i) for 1 i N. Compute the corresponding U(t i) U i points ( ) Ti A U i = ln T 0 A and plot them as a scatter plot in MatLab. Note the first value, U 1 = ln T0 A T0 A = ln(1) = 0. So our line has U intercept 0. Hence, our line is of the form y = mt and we have to find a good candidate for the slope m. This slope will then be used in our cooling model. From your data, you now have a collection of pairs (t i, U i) for 1 i N. We can find a line which comes close in an optimal way to all of this data (although the line does not have to include all the data!) by using a bit of calculus. At each time, the line has the value mt i. The discrepancy or error between the actual U value and the line value is then U i mt i. We want the cumulative error between our line and the data, so we don t want errors to cancel. Hence, we could choose an error term like U i mt i or (U i mt i) 2. Both of these are fine, but the squared one is differentiable which will allow us to use calculus methods. Define the energy function E(m) where m is the slope to be E(m) = N (U i mt i) 2. This is a nice function and so let s find where this function has a minimum by setting its derivative is zero.
Setting the derivative to zero, we find de N dm = 2 (U i mt i) ( t i) = 0. Simplifying a bit, we have N ( U it i = m ti 2 Solving for the critical point m, we find ). m = Uiti t2 i Finally, it is easy to see d 2 E dm 2 = 2 N ti 2 > 0. for all choices of m. Hence, the value m which is the critical point must be the global minimum Hence, the optimal slope is m = Uiti t2 i Then we can see how good our model is by plotting the model solution T (t) = T (t) = A + (T 0 A)e m t on the same plot as the actual data.
Let s see how we can manage some experimental data. Save your experimental data in a file with two columns. Column one is for time and column two is for the temperature of your liquid. Create a new file in Matlab and call it Newton.dat or some other name. Place it in your class folder. For a typical liquid (orange juice, water, tomato juice etc), we might collect the data here 0. 0 205 0. 5 201 2. 0 201 5. 0 190 8. 0 178 1 0. 0 175 1 3. 0 167 1 5. 0 161 2 5. 0 141 3 0. 0 135 4 0. 0 127 5 0. 0 117 6 5. 0 108 8 0. 0 100 9 5. 0 95 1 1 0. 0 89 1 3 0. 0 83 1 6 5. 0 80 We have the ambient or room temperature is 76 degrees for our experiment. load the data and generate the plot of the data % l o a d i n t h e e x p e r i m e n t a l data from t h e % f i l e Newton. dat as two columns >> Data = l o a d ( Newton. dat ) ; % use t h e f i r s t column as time >> time = Data ( :, 1 ) ; % use t h e second column a s t e m p e r a t u r e >> Temperature = Data ( :, 2 ) ; % g e n e r a t e a p l o t o f t h e e x p e r i m e n t a l data >> p l o t ( time, Temperature, o ) ; % s e t x l a b e l >> x l a b e l ( Time in Minutes ) ; % s e t y l a b e l >> y l a b e l ( Temperature in Fahrenheit ) ; % s e t t i t l e >> t i t l e ( Newton Law Of Cooling Experimental Data ) ;
We see the plot of the measured data here: From the theory we have discussed, ( we ) know we should graph the T A transformed data given by log T0 A where A is the room temperature, T and T0 are the temperature and initial temperature of the liquid, respectively. Here A = 76 and T0 = 205. Thus, T0 A = 129. Here is how we do this in Matlab: % for t h i s data, T 0 A = 205 76 = 129 >> A = 7 6 ; >> LogTemperature = l o g ( ( Temperature A) / ( 129. 0 ) ) ; >> p l o t ( time, LogTemperature, o ) ; >> x l a b e l ( Time in Minutes ) ; >> y l a b e l ( Transformed V a r i a b l e l n ( (T A) /( T 0 A) ) ) ; >> t i t l e ( Transformed Data Versus Time ) ;
You can see this transformed data here: Then, look for the best straight line through the plot making sure you have the line go through the point (0, 0) at the top. The optimal slope is then m = Uiti N. t2 i In MatLab, we can add up all the entries in the variable U and time using the sum command. The optimal slope calculation in MatLab is then >> mstar = sum ( LogTemperature. time ) /sum ( time. time ) mstar = 0.0215 where the variable LogTemperature plays the role of U. Note time and LogTemperature are vectors so we use.* to do component wise multiplications!
The syntax LogTemperature.*time means to multiply each component of LogTemperature and time separately to create the new column of values LogTemperature(1) time (1) LogTemperature(N). time (N) The command sum applied to this column then creates the sum Uiti like we need. A similar thing is happening with the term sum(time.*time). The model is thus u(t) = 76.0 + 129 e 0.0215t which we enter in MatLab as % compute t h e model >> u2 = 7 6.0 + 129.0 exp ( mstar time ) ; Then we plot both the experimental data and the model on the same plot, % p l o t t h e model and t h e measure data on t h e same p l o t >> p l o t ( time, u2, r, time, Temperature, o ) ; >> x l a b e l ( Time In Minutes ) ; >> y l a b e l ( Temperature in Fahrenheit ) ; >> t i t l e ( F i t o f Newton Law o f C o o l i n g Model To Data : Data = o ) ; Looks pretty good! We could also have added a legend like legend( Model, Data, Location, BestOutside ); but we didn t show that. You should do that though in your report so it is really easy to see what is going on.
Our final plot! Here is all the code without comments! >> Data = l o a d ( Newton. dat ) ; >> time = Data ( :, 1 ) ; >> Temperature = Data ( :, 2 ) ; >> p l o t ( time, Temperature, o ) ; >> x l a b e l ( Time in Minutes ) ; >> y l a b e l ( Temperature in Fahrenheit ) ; >> t i t l e ( Newton Law Of Cooling Experimental Data ) ; % for t h i s data, T 0 A = 205 76 = 129 >> A = 7 6 ; >> LogTemperature = l o g ( ( Temperature A) / ( 129. 0 ) ) ; >> p l o t ( time, LogTemperature, o ) ; >> x l a b e l ( Time in Minutes ) ; >> y l a b e l ( Transformed V a r i a b l e l n ( (T A) /( T 0 A) ) ) ; >> t i t l e ( Transformed Data Versus Time ) ; >> mstar = sum ( LogTemperature. time ) /sum ( time. time ) ; >> u2 = 7 6.0 + 129.0 exp ( mstar time ) ; >> p l o t ( time, u2, r, time, Temperature, o ) ; >> x l a b e l ( Time In Minutes ) ; >> y l a b e l ( Temperature in Fahrenheit ) ; >> t i t l e ( F i t o f Newton Law o f C o o l i n g Model To Data : Data = o ) ;
Due Date: Friday December 8, 2017. We will use the following time and temperature data: This data gives you a set of 18 {ti, Yi} data pairs. The ambient temperture is 68 degrees. 0. 0 209 0. 5 202 2. 0 196 5. 0 188 9. 0 177 1 1. 0 162 1 3. 0 155 1 5. 0 145 2 5. 0 131 3 0. 0 120 4 0. 0 111 5 0. 0 103 6 5. 0 94 8 0. 0 83 9 5. 0 78 1 2 0. 0 74 1 3 0. 0 73 1 6 5. 0 71 Let E(m) = 18 18 (Ui mti) 2 and F (m) = Ui mti Your project is this: Find the value of m that optimizes E using our calculus tools for finding extremal values. Prove this value gives a minimum. Find the values of m that optimize F using our subdifferential tools for finding extremal values. Prove this value gives a minimum. For the differentiable case, show all the MatLab code and the three appropriate graphs: the data, the transformed data, the model and data on the same graph. For the nondifferentiable case, all the work is done by hand as we have done in smaller problems for homework. Graph your model and the data on the same graph for this one too. Comment on the difference in these two optimal cooling parameter solutions.