% SIMIODE-TeacherStudent-Template.tex and simiode.cls for LaTeX2e
% Version 22 November 2016.
%
% This template is to be used with the  class file "simiode.cls".
%
% The latest version of this class and template files
% can be found at
%
%       <http://www.SIMIODE.org> in the Author section.
%
% A "Quick Start Guide" appears below.
%
% This file must be processed with version LaTeX2e or higher.
% Appreciation to Mark Frantz, IUPUI; John Thoo, Yuba College; and Eric Sullivan, Carroll College.
%
\documentclass{simiode}
%
% With this version of the tex file and the associated SIMIODE.cls file you can produce BOTH a Student Version and a Teacher Version of your modeling scenario or technique narrative.
%
% Student Version contains the title STUDENT VERSION along with the NAME OF SCENARIO, with no abstract, no keywords, no tags, no author identifiers, and no COMMENTS section. The Student Version contains only the STATEMENT of the modeling scenario only with appropriate figures, data, instructions, and perhaps a bibliography appropriate for student resourcing, but nothing in the bibliography which would "give away" the nature of the modeling scenario, etc.
%
%The Teacher Version contains the material in the Student Version, namely the title NAME OF SCENARIO, now headed with   TEACHER VERSION, but also full author  identification, abstract, key words, tag words, and, following the STATEMENT, a section of COMMENTS which can be discussion of presentation  ideas, "solutions," techniques, etc.
%
% Authors can prepare a full Teacher Version using the notions immediately below  to create a pdf for review, but in review please eliminate all information about the author as we use a double-blind referee system. Such information will be restored when accepted and published in SIMIODE at www.simiode.org.
%
%***********   Toggle the following line to turn the teacher version on (1) or off (0). ***********
%
\def\TeacherEdition{0} % Toggle this line's value.
\newcommand{\teacher}[1]{\ifnum\TeacherEdition=1 #1 \fi}
%
% The \teacher{ } command wraps any text that will appear only in the teacher version of
% the document. See this file for examples. This has been done for you in the document below.
% Rename the pdf after you compile each final version.
%
\usepackage{amsmath,amssymb}
\usepackage{color}
\usepackage{graphicx}
%\usepackage{hyperref}
\usepackage{url}
%
\renewcommand{\baselinestretch}{1.3}
%
% NOTE regarding macros %%
%
% Any macros defined for your paper should be contained in
% the top matter. Likewise, any environment definitions such
% as \newtheorem or \newenvironment should also go in the
% top matter.
%
% Do not \input your macros as separate files within your
% final version because more files make it harder for the
% editors and users to keep track of and/or modify and
% append your paper.
%
% Top matter is above and the beginning of the document below.
%
\begin{document}

\newpage
%
% You only need to change the NAME OF SCENARIO in the next line and delete the footnote.
% See above for instructions on toggling from Teacher Version to Student Version.
%
\title{\ifnum\TeacherEdition=1 TEACHER VERSION
%\footnote{DELETE THIS FOOTNOTE BEFORE SUBMISSION.  In the \TeX \, source code there is a toggle/option to produce a Teacher Version or a Student Version by ``carving'' out with  $\backslash$teacher\{\} that material which should only appear in the Teacher version. See the source code.}
\else STUDENT VERSION \fi\\Home Heating}



\markboth{Home Heating}{Home Heating}

\author{Kurt Bryan\\
Rose-Hulman Institute of Technology\\
Terre Haute IN47840 USA\\
kurt.bryan@rose-hulman.edu
}

\makeStitlePDFLaTex

\begin{abstract}
This project concerns using Newton's Law of Cooling to model the heating of a house. In particular, if one is going away for awhile, is it more economical to leave a house
at a desired temperature or reheat it upon return? Both scenarios are analyzed in a series of exercises. The mathematics used is simply the Newton's Law of Cooling differential
equation, with possible modification
for an active heat source, and basic integration. A computer algebra system can be helpful, but is not essential. This project can be done in class, or perhaps better yet, started in class as part of a homework assignment.

\end{abstract}

\section*{SCENARIO DESCRIPTION}
\vspace*{-.2 true cm}

Suppose you're going away on vacation over Christmas, for a total of four days (96 hours).
When you leave the house the inside temperature is a comfortable $21^\circ{}$C; you want it at that same temperature when you return.
Since it's winter, this means you'll have to run the furnace. To minimize the costs/fuel consumption, should you
\vspace*{-.2 true cm}
\begin{enumerate}
\item Just leave the furnace on (thermostat set to $21^\circ{}$C the whole time you're gone), or should you
\item Set the thermostat so the furnace stays off for most of the four days, but comes on just in time to heat the house back to $21^\circ{}$C when
you return at $t=96$ hours?
\end{enumerate}
\vspace*{-.2 true cm}

Scenario 2 assumes there's no problem with letting the house get cold, e.g., burst pipes, tropical plants, small pets, etc. It also assumes you have a suitably programmable thermostat.

In summary, the central question of interest is
\begin{quote}
\textit{Is it more economical to keep the house warm, or to reheat it?}
\end{quote}
%\section*{Submission Version}

\noindent {\bf Newton's Law of Cooling}\\

Newton's Law of Cooling states that if an object with temperature $y(t)$ (here $t$ is time, $y$ temperature) sits in an
environment with ambient temperature $A$ then $y(t)$ obeys, to good approximation,
\begin{equation}
\label{newton1}
\frac{dy}{dt} = -k(y(t) - A)
\end{equation}
where $k>0$ is a constant. The ambient temperature $A$ might be a function of time. There are many assumptions implicit in the model, among them that
the object has a single well-defined temperature throughout. Thus in what follows we'll treat the object as being ``negligible'' in size, even though
it's a house!\\\ \\
{\bf Exercise 1:} Solve (\ref{newton1}) with initial condition $y(0)=y_0$; assume $A$ is constant. What is the long-term behavior of the solution?
How does it depend on $k$?\\\ \\
{\bf Exercise 2:} Suppose we measure time $t$ in hours and $y(t)$ denotes the temperature of the house in degrees Celsius.
 Take $t=0$ as the time you leave the house, $y(0)=21$, $k=0.01$, and suppose $A=0$. What are the units on $k$? Use the solution from Exercise 1
 to determine how cold the house will be
when you return at time $t=96$ hours. Pretty cold, huh?\\\ \\
{\bf Modifying Newton's Law of Cooling for a Heat Source}\\

However, the house has a furnace, so in our model we can suppose that heat energy is being actively generated at some rate.
Let $y(t)$ be the (inside) temperature of the house and $A$ the ambient (outside) temperature.
In this case Newton's Law of Cooling (\ref{newton1}) can be modified as
\begin{equation}
\label{newton2}
 y'(t) = -k(y(t) - A) + r(t)
\end{equation}
where $r(t)$ is a function that is proportional to the rate of
energy generation, which we allow to be a function of time.  (If you want to be precise,
in the simple case that the object has mass $M$, specific heat $c$, and is of negligible extent, $r(t) =
\frac{E(t)}{Mc}$, where $E(t)$ is the rate of energy generation).

In what follows we will assume temperature is measured in degrees Celsius and, given the scale of the problem, time is measured in hours.
The function $r(t)$ itself then has units of degrees per hour.
One might think of $r(t)$ as follows: if at some instant $t=t_0$ we have $y(t_0)=A$
(that is, the house is at ambient temperature) and the furnace is on, then from (\ref{newton2}) we have $y'(t_0)=r(t_0)$, so $r(t_0)$ quantifies the rate
at which the furnace is raising the temperature of the house at that instant.\\\ \\
{\bf Analysis of Scenario 1: Keeping The House Warm}\\

Suppose the house temperature $y(t)$ obeys (\ref{newton2}); $r(t)$ would be proportional to the rate at which the furnace consumes energy. Again throughout the
analysis suppose, for simplicity, that $A=0^\circ{}$C and $k=0.01$ (based on watching the author's house cool on a cold winter day when the power went out).

In Exercise 2 above you of course found that the house is quite cold if you leave the heat off for four days. But
you want the house to be at $21^\circ{}$C, the same as when you
left. How much energy will be needed to heat the house if you leave the furnace set to maintain $21^\circ{}$C the whole time?\\\ \\
{\bf Exercise 3:} Suppose $r(t)=r_0$ in
(\ref{newton2}), where $r_0$ is a constant chosen so as to
maintain a constant $21^\circ{}$C in the house---what constant
$r_0$ is required? Hint: choose $r_0$ so that $y(t)=21$ is an equilibrium solution to (\ref{newton2}).\\\ \\
{\bf Exercise 4:} Draw a phase portrait for (\ref{newton2}) assuming that  $r(t) = r_0$  is constant.  What does an equilibrium represent?\\\ \\
{\bf Exercise 5:} Note that $r(t)$ is directly proportional to the power
output of the furnace, and so ${\displaystyle \int_0^{96}
r(t)\,dt}$ is directly proportional to the total energy expended
by the furnace during the four days, which itself should be
proportional to the cost of running the furnace for that time
period.  Compute this integral (hint: this is trivial).  The result is a
measure of the cost of keeping the house at $21^\circ{}$C.\\



A note for the picky: you can't run a typical furnace at any power you want---it's either on or off. So you can't choose any $r_0$ you want, but you can fake it: if a given choice for $r_0$ corresponds to, say, 50 percent of the furnace maximum output, you could run the furnace full on for 30 minutes, then off for 30 minutes, then on for 30, etc., i.e., run it at a 50 percent duty cycle.  Over a four day time span it would look pretty much like the furnace running at 50 percent.\\\ \\
{\bf Analysis of Scenario 2: Reheat The House}\\

Here's an alternate strategy for making sure the house is $21^\circ{}$C when you return:  Turn the heat off when you leave,
but program the thermostat to turn on the furnace full blast at
some time $t=t_1$, with $t_1<96$, to reheat the house to $21^\circ{}$C at exactly time $t=96$ when you return home.  The value of
$t_1$ should be chosen as large as possible (i.e., turn the furnace on at
the last possible minute). Of course this assumes, somewhat unrealistically,
that you know the outside ambient temperature at all times, but it's a start.

Will this be more or less efficient
than the previous strategy? Answer the following questions to find out!\\\ \\
{\bf Exercise 6:} Suppose the furnace is off from time $t=0$ to some
unspecified time $t=t_1<96$.  Let's use $y_1(t)$ to denote the
temperature of the house during this time period, so $y_1(t)$ obeys (\ref{newton1}) with
$y_1(0)=21$. Use the results of Exercise 1 to write out $y_1(t)$ explicitly  when  $k = 0.01$  and $A = 0$.\\\ \\
{\bf Exercise 7:} At some time $t=t_1$ we need to turn the furnace on ``full blast'' to reheat the house. Assume that
in this case the function $r(t)=3$ degrees per hour (meaning the furnace is capable of heating the
house at a max rate of 3 degrees per hour, at least when $y(t)=0$). From time $t=t_1$ to time $t=96$
the temperature of the house will be given by a function $y_2(t)$ that satisfies the DE (\ref{newton2})
with the \textit{final condition} $y_2(96) = 21$. Solve (\ref{newton2}) with $y_2(96)=21$ to find $y_2(t)$.

Could we simply have modeled $y_2(t) = 3t + b$,  where  $b$  is chosen so that  $y_2(96) = 21$?  Explain.\\\ \\
{\bf Exercise 8:} Refer to Figure \ref{fig1}. The function $y_1(t)$ gives the temperature of the house for $0\leq t\leq t_1$,
while $y_2(t)$ gives the temperature for $t_1\leq t\leq 96$. The value of $t_1$ when the furnace should be turned on is dictated
the condition $y_1(t_1) = y_2(t_1)$ (think: why is this appropriate?)
Use this observation to find $t_1$.\\\ \\
\begin{figure}[ht]
\centerline{\includegraphics[width=0.5\textwidth]{1-079-Fig1.jpg}}
\caption{Function $y_1(t)$ (red), $y_2(t)$ (blue) for $0\leq t\leq 96$.}
\label{fig1}
\end{figure}
\ \\
If the furnace does not shut off, will the temperature in the house continue to rise without bound after $96$ hours?\\\ \\
{\bf Exercise 9:}  As in Scenario 1, a measure of how much it costs to heat the
house is given by ${\displaystyle \int_0^{96} r(t)\,dt}$.  What is the integral in
this case? (Note, $r(t)\equiv 0$ for $t<t_1$, so you really only
need to worry about $t_1\leq t\leq 96$).\\\ \\
{\bf Exercise 10:} Compare the total ``energy'' usage from Exercise 5 to that from Exercise 9. Which is more economical, reheating the house or just
leaving it at $21^\circ{}$C?\\\ \\
{\bf Exercise 11:} (Harder!) You're going to be gone
from time $t=0$ to time $t=T$.   The ambient temperature outside
is $A$ (constant). Let the initial temperature of the house be $y_0$, which
also happens to be the temperature you want it when you return;
assume $y_0>A$.  The cooling constant is simply $k$, and the
furnace is capable of a maximum output of $r(t)=r_M$, where
$r_M\geq k(y_0-A)$ (this ensures that the furnace is at least
capable of maintaining temperature $y_0$!)

Is there ANY combination of constants
$T, p_0, A, k$, and $r_M$ that make it more economical to just
leave the furnace on while you're gone? Or can you prove that this
strategy is never beneficial?

\teacher{
\section*{COMMENTS}

For Exercise 3 it's necessary to take $r_0=0.21$ (units---degrees Celsius per hour) to keep the house at $21^\circ{}$C. Over the course of 96 hours the total energy used (or cost) is
proportional to $(0.21)(96) = 20.16$. In the ``reheat'' Scenario, we find $y_1(t) = 21e^{-0.01t}$ while $y_2(t)=300-728.663 e^{-0.01t}$. They intersect at $t_1\approx 91.584$, that is
the furnace should come on about $4.416$ hours before you return, for a total ``energy'' usage of $13.25$. The conclusion is that it is more economical to reheat the house, rather than keep it at a constant temperature.

This project can be done without technology, but my students have Maple and found it beneficial to plot things as they went along, to make sure answers were realistic. I usually devote a class to this activity, then send them home to finish and write up their results. The main difficulty students have had is understanding the condition $y_1(t)=y_2(t)$ in Exercise 8
(why is the continuity of temperature reasonable?), so I show them Figure \ref{fig1}. Exercise 11 is somewhat open ended; however, one can show (under much more general conditions than given here) that it is
always more beneficial to let the house cool and then rewarm it. This illustrates the general observation that thermal systems don't have ``momentum'' the way mechanical systems do.
It's also a good example of a ``bang-bang'' control problem, in which the optimal control for a physical system should be either full on or full off.

A sketch of the proof for the assertion that rewarming the house is optimal, even under very general assumptions, is this: First, we can make a change of variable $y\longleftarrow y-A$ to reduce to the case $A=0$.
Let the house (or whatever) obey a differential equation of the form
$y'(t) = -f(y(t)) + r(t)$ where $f$ is a continuously differentiable function that is strictly increasing and with $f(0)=0$. This is a rather general model appropriate to a universe where heat flows from hot to cold! We assume $y(0)=y_0$ is the initial (and desired temperature) for the house. The function $r$ is under our control, and we assume that $0\leq r(t)\leq r_M$ (the house is heated, no air conditioning, and the heater has a maximum output). We need to ensure that $y(T)=y_0$ at some later time $t=T$. The total cost of heating the house will be the functional $C(r) = {\displaystyle \int_0^T r(t)\,dt}$.

Now note that from $y'(t) = -f(y(t)) + r(t)$ we have
\begin{equation}
\label{Cdef}
C(r) = \int_0^T (y'(t) + f(y(t)))\,dt = y(t)|_{t=0}^{t=T} + \int_0^T f(y(t))\,dt = \int_0^T f(y(t))\,dt
\end{equation}
since $y(0)=y(T)=y_0$. The goal is to choose $r(t)$ to minimize the quantity $C(r)$.

Let $r^*(t)$ be that piecewise constant function defined by $r^*(t)\equiv 0$ for $0\leq t<t_1$ and $r^*(t)=r_M$ for $t_1\leq t\leq T$, where $t_1$ is chosen so that $y(T)=y_0$ (it's not hard to show $t_1$ is defined and unique.) Let $y^*(t)$ denote the corresponding temperature. The claim is that $C(r^*)\leq C(r)$ for any other control function. To see this, suppose
that for some $r(t)$ defined on $[0,T]$ we have $r(t)\geq r^*(t)$ for $0\leq t<t_1$. It's intuitively clear (and one can prove with a monotonicity argument) that then $y^*(t)\leq y(t)$ for $t\in [0,t_1]$. Similarly for $t\in [t_1,T]$ we must have $y(t)\geq y^*(t)$ (for if $y(t')<y^*(t')$ at some time $t'$ then $r(t)$ would have to exceed $r_M$ to attain $y(T)=y_0$.)
All in all then we have $y^*(t)\leq y(t)$ for all $t\in [0,T]$, and so from (\ref{Cdef}) and the fact that $f$ is strictly increasing we find $C(r^*)\leq C(r)$.
}





\end{document}
