% maple lab 2 S2015, swamp cooler
\documentclass[leqno]{article}
\input{linalg.sty}
\usepackage{graphicx}
\usepackage{epstopdf}
%\usepackage[active]{srcltx}%          MikTeX win98 and YAP.EXE
\def\rf#1{(\ref{#1})}
\def\BF#1{{\bf #1}}
\def\Prob#1#2{\par\bigskip\par\noindent
{\Large\sf Problem #1}. {\bf #2}\par}
\parskip=3pt
\def\MAPLE{{\tt maple}}
% \begin{topics}{template} ... \end{topics}
% used like enumerate, itemize, description environments
% The item[] is never optional!
%
\pagestyle{plain}
\setlength{\textheight}{9.8in}
\newcommand{\miniFigureEPS}[3]
% #1=title
% #2=eps file name
% #3=label to be used for figure
{% begin command \miniFigureEPS
    \label{#3}%
 \begin{center}   \input{#2}
     \par
     #1
     \end{center}
}% end of command \miniFigureEPS

\begin{document}
\thispagestyle{empty}

 {\bf Name~}\underline{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}\hfill
 %{Class Time~}\underline{~~~~~~~~}\newline


\begin{center}
\bf Math 2280
\bf Maple Project 2: Newton Cooling, Swamp Cooler \\
{\small\bf Spring 2015}
\end{center}


{\bf Due date}: See the internet due dates.

{\bf References}: Edwards-Penney 2nd, pages 55--57. Code in \MAPLE{}
appears in \verb|2280mapleL2-swamp-cooler-S2015.txt| at URL
\verb|http://www.math.utah.edu/~gustafso/|. This document:
\verb|2280mapleL2-swamp-cooler-S2015.pdf|.

\miniFigureEPS
{An evaporative cooler, used in low-humidity regions of the United States instead of refrigerated air conditioning.}
{cooler.xfig.pstex_t}
%{2-8-1}% uses control sequence \AABB
{fig2.8.1}

{\bf The Problem and Model}. The project is to determine an
approximation for the indoor temperature $u(t)$ in a
building equipped with an evaporative cooler. The model uses Newton's cooling law, insulation data $k_1$,
cooler data $k_2$, symbol $k=k_1+k_2$, a formula for the ambient outside temperature $A(t)$ and a formula for the cooler air temperature $C(t)$ (see the
background section {\em infra}):
\begin{equation}\label{newtoncoolingone}
\begin{array}{l} u'(t)+ku(t)=k_1A(t)+k_2C(t),\\
  u(0)=u_0. \end{array}
\end{equation}

{\bf Assumptions and Notation}.
\begin{itemize}
\item
 The inside temperature is the wall thermometer reading $u(t)$, where $t$ is in hours
measured from midnight $t=0$.
\item
Symbol $u_0$ is the wall thermometer reading
at midnight.
\item
The model assumes that no heat sources or heat sinks
are present inside the building, except for the evaporative cooler.
\item The ambient outside air temperature is called $A(t)$.
It varies from a low of $m=60$ degrees to a high of $M=98$
degrees with the low and high at $3$am and $3$pm, respectively. Let
$\omega_0=\pi/12$. The ambient temperature model will be
$$\begin{array}{lcl}
 A(t)&=&\dd\frac12(M+m)-\frac12(M-m)\cos \omega_0 (t-3)\\[2ex]
     &=& \dd 79 - 19\cos \omega_0 (t-3).
 \end{array}
$$
Then $A(t)$ satisfies $M=\max A(t)=A(15)=98$, $m=\min A(t)=A(3)=60$
and $A(t)$ is $t$-periodic of period $24$ hours.
For use in \MAPLE{}, define a function of two variables
\begin{center}\tt
 AA:=unapply(79-19*cos (omega* (t-3)),(t,omega));
\end{center}
Maple function {\tt AA(t,omega)} is useful to maintain the symbol $\omega$ in displays.
\item
The building is assumed insulated, the average insulation factor
being represented by a Newton cooling constant $k_1$, usually $0.2
\le k_1 \le 0.5$.
The expected temperature change due to insulation is $k_1(A(t)-u(t))$.
\item
 Let $C(t)$ be the evaporative cooler air temperature. During operation, the evaporative cooler
 is assumed to deliver air $20$\% cooler than the ambient temperature, which becomes the assumption $C(t)=0.8A(t)$.
 The lower temperature is due to heat loss from water evaporation.
The expected temperature change due to cooler operation is
$k_2(C(t)-u(t))$, where $k_2$ is a Newton cooling constant.
\item
Symbol $k=k_1+k_2$. Symbol $k_3=k_1+0.8k_2$.
\item
Symbol $u_h(t)=c e^{-kt}$ denotes the
general solution of the homogeneous equation $u'+ku=0$.
\item
Symbol
$u_p(t)$ stands for a particular solution of $u'+ku=k_3A(t)$.
\end{itemize}

\Prob{L2.1}{(Solution Formulas for $u_p$ and $u$)} Derive by hand, using
\MAPLE{} assist for values of integrals, an explicit symbolic formula
for $u_p(t)$. Display a final formula for $u=u_h+u_p$ which depends only
on $t$, $u_0$, $k$, $k_3$ and $\omega$. Check your hand answer for $u$ in
\MAPLE{}. The only \MAPLE{} assist in this problem is
\MAPLE{} integration and the \MAPLE{} answer check.

\Prob{L2.2}{(Steady-State Periodic Solution)} Derive by hand a
formula for the steady-state periodic solution $u_{\mbox{ss}}$ of
$u'+ku=k_3A(t)$. There is no \MAPLE{} assist in this problem, it is
all done by hand from the answer in L2.1. The results:
$$
\begin{array}{rcl}
u_{\mbox{ss}}(t) &=& \dd\frac{k_3}{k}\left(79 -{\dd\frac{19k}{k^2+\omega_0^2}}(k\cos\omega_0
(t-3)+\omega_0\sin\omega_0 (t-3)\right), \\[2ex]
 u(t) &=& Ce^{-kt} + u_{\mbox{ss}}(t),\\
C &=&u_0-u_{\mbox{ss}}(0). \end{array}
$$

\Prob{L2.3}{(Indoor-Outdoor Variation)} Compare in a \MAPLE{} graphic
oscillations of the indoor temperature $u(t)$ and the outdoor
temperature $A(t)$ over a $48$-hour period assuming $k_1=0.32$, $k_2=0.5$, $u_0=76$,
$\omega=\pi/12$. Include in the plot four horizontal lines for the
maximum and minimum temperatures for each of $u(t)$ and $A(t)$. Report
the indoor and outdoor temperature variations from this $48$-hour plot
(max minus min in each case). Report the time delay between the indoor
and outdoor temperatures, using this same plot.

\Prob{L2.4}{(Swamp Cooler)} Assume $\omega=\pi/12$ and $k_2=0.5$. Consider all
insulation constants $k_1$ in the range from $0.2$ to $0.48$. Suppose the
inside temperature is $76$ degrees at midnight. Report approximate ranges of hours and insulation
constant $k_1$, during the first 72 hours, for
which the indoor temperature is at or below $70$ degrees. Justify
your logic used to find the ranges, in a short paragraph.
Illustrate with a computer graphic. \vfill

{{\sf Staple this page on top of all hand and maple work.}
\newline
\medskip
Background, problem notes and sample maple code are on the following
pages \ldots}
\newpage

\section*{Background}
{\bf Newton Cooling Model}.
Newton's law of cooling is:
\begin{quote}\em
The rate of change
of a body's temperature is proportional to the difference between the
ambient temperature and the body's temperature.
\end{quote}
This implies that $du/dt$ is the sum of two rates, one due to the insulation and one due to the
evaporative cooler. A model for the
indoor temperature $u(t)$ is given by $du/dt=k_1(A(t)-u(t))+k_2(C(t)-u(t))$, $u(0)=u_0$,
which can be rearranged as
\begin{equation}\label{newtoncooling}
u'(t)+ku(t)=k_3A(t),\quad k=k_1+k_2,\quad k_3=k_1+0.8k_2, \quad u(0)=u_0.
\end{equation}

{\bf Indoor Temperature $u(t)$}.
The integrating factor method for linear equations
applies to find the general solution by these steps:

\def\AA{XX$u=u_0e^{-kt}+e^{-kt}\int_0^t k_3A(r)e^{kr}\,dr$}
\begin{topics}{\AA}
\item[$u'+ku=k_3A(t)$]  Copy the differential equation.
The integrating factor is $W=e^{kt}$.

\item[$\dd\frac{(e^{kt}u)'}{e^{kt}}=k_3A(t)$]  Integrating factor method: replace $u'+ku$ by $(Wu)'/W$.

\item[$(e^{kt}u)'=k_3A(t)e^{kt}$]  Clear fractions.

\item[$e^{kt}u=u_0+\int_0^t k_3A(x)e^{kx}\,dx$]
Integrate both sides with respect to $t$. Apply the Fundamental Theorem
of Calculus. Use $u(0)=u_0$.

\item[$u=u_0e^{-kt}+e^{-kt}\int_0^t k_3A(x)e^{kx}\,dx$]
Divide to isolate the {\em explicit solution} $u$.

\end{topics}

Let $u_h(t)=u_0e^{-kt}$, which is a solution of $u'+ku=0$. Let $u_p(t)=k_3e^{-kt}\int_0^t
e^{kx}A(x)dx$, a particular solution of the nonhomogeneous
differential equation $u'+ku=k_3A(t)$. Then the indoor temperature
$u = u_h + u_p$ depends on the time $t$, the initial temperature
$u_0$, the insulation constant $k_1$, the evaporative cooler constant $k_2$ and the frequency $\omega$
(which is fixed at $\pi/12$). Because $k=k_1+k_2$ and $k_3=k_1+0.8*k_2$, then write $u=u(t,u_0,k,k_3,\omega)$ to
emphasize the dependence. In \MAPLE{}, advantages exist for adding
the variable name $\omega$, which is later set equal to value
$\omega_0=\pi/12$. Write $u$ as \fbox{\tt U(t,u0,k,k3,omega)} for use
in \MAPLE{}.

{\bf Steady-state solution}. The steady-state solution
$u_{\mbox{ss}}$ is an expression obtained from the general
solution formula $u=u_h+u_p$ by dropping all terms containing a
negative exponential. It depends on $t$, $k$, $k_3$ and $\omega$ [but not $u_0$]. This
expression is known to be a solution of the differential equation,
independent of any arbitrary constants, which represents the {\bf
observed temperature} after a long time.  In short,
$u_{\mbox{ss}}$ is independent of $u_0$. Theory provides the following result.
\begin{quote}\sf
{\bf Theorem} (Unique Periodic Solution) Assume $p\ne 0$ is a constant and $q(x)$ is continuous and $T$-periodic [$q(x+T)=q(x)$]. Then the differential equation
$ \dd\frac{dy}{dx} +py = q(x)$
 has a unique $T$-periodic
solution $y(x)$ given by the initial value
$$y(0)=\left(e^{pT}-1\right)^{-1}\int_0^T e^{pt}q(t)dt.$$
\end{quote}


%\noindent
%\begin{tabular}{p{3.35in}} \hline\\
%\end{tabular}
%\smallskip

\newpage

\section*{Problem Notes}



\subsection*{Notes on L2.1}

A derivation by hand is expected, which parallels the derivation above. The difference is the inclusion of fine details, including integration results, finally
giving a formula for $u_h$ and a formula for $u_p$. Integration for the
$u_p$ formula is referenced to an attached maple worksheet appendix. The
answer check references a second attached worksheet.

Because many students want to know how to do the integration, based upon
a calculus background, more information is provided here. The
integration problem can be solved by hand using the book's integral
table:
$$u_p(t)=k_3e^{-kt}\int_0^t e^{kx}\left(79-19\cos \left(\omega(x-3)\right)\right)dx.$$
A change of variable $u=x-3$ allows use of integral table entry $\int
e^{au}\cos bu\,du$. The symbol $\omega$ will be set to $\pi/12$, but for
simplicity, use symbol $\omega$ throughout.

You are asked to use {\tt maple} to evaluate the integral. Its table lookup method is superior
to the hand method above, in that no change of variable is required to
obtain the answer. This method is accurate and avoids primary pitfalls
in using a book table. A coding example appears below, which moves the
factor $k_3e^{-kt}$ inside the integrand, in order to automatically
perform simplifications.
\begin{verbatim}
 # maple integral table lookup
 unassign('omega','t','u0','k','k1','k2','k3','x');
 integrand:=(79-19*cos(omega*(x-3)))*k3*exp(k*x-k*t);
 integral:=int(integrand,x=0..t);
\end{verbatim}
The formulas for $u_h$ and $u_p$ are used again in L2.2 in order
to derive the steady-state solution. Your answer for $u=u_h+u_p$ {\em must
contain} symbols \fbox{\tt t, u0, k, k3, omega}.

The answer check in \MAPLE{} is organized as follows. The complications
of setting $\omega=\pi/12$ are avoided here by leaving $\omega$ as a
symbol, since it does not affect the answer check.
\begin{verbatim}
 # Test LHS=RHS for u'+ku=k3 A.
 unassign('t','C','omega','k','k1','k2','k3'):
 k:=k1+k2:k3:=k1+0.8*k2:
 uh:=C*exp(-k*t):
 up:=integral: #(explicit answer from L2.1)
 myANS:=uh+up:
 LHS:=diff(myANS,t)+k*myANS:
 RHS:=k3*(79-19*cos(omega*(t-3))):
 simplify(expand(LHS-RHS));
\end{verbatim}
A successful test of $LHS=RHS$ produces answer {\em zero}, or an
expression that reduces to zero.


\subsection*{Notes on L2.2}

The steady-state solution is derived from the hand-generated
symbolic solution $u=u_h+u_p$ in L2.1 by dropping all terms that
contain the negative exponential factor $e^{-kt}$. The answer, where
$\omega_0=\pi/12$:
$$u_{\mbox{ss}}=\frac{k_3}{k}\left(79
-\frac{19k}{k^2+\omega_0^2}(k\cos\omega_0
(t-3)+\omega_0\sin\omega_0 (t-3))\right).$$

To get \MAPLE{} to report the above formula, it is essential to
evaluate everything with $\omega$ as a {\em symbol}, to wit, use
in \MAPLE{} the statement \fbox{\tt unassign('omega'):}. {\bf
Beware} of writing \fbox{\tt omega:=Pi/12}, which defines $\omega$
to be a constant, unless you undo the effect immediately
afterward. Maple's \fbox{\tt unassign} can be used to erase
assignments.

Maple is unable to evaluate \fbox{limit(exp(-k*t),t=infinity)} as
zero, because the expression contains $k$, an unevaluated symbol. This
is why you are asked to report the steady-state solution manually, by
dropping terms from previously obtained answers. Saying \fbox{\tt assume(k>0)} fixes the limit problem.

%up:=k3*(79*k^2+79*omega^2-19*k^2*cos(omega*t-3*omega)
%-19*k*omega*sin(omega*t-3*omega))/(k*(k^2+omega^2));

\newpage

\subsection*{Notes on L2.3}

The outside temperature  $A(t)$ ({\tt AA(t,omega)} in \MAPLE{})
and the solution $u=U(t,u_0,k,k3,\omega)$ obtained in L2.2 can be
coded in \MAPLE{} as follows:
\begin{verbatim}
 unassign('t','u0','k','k1','k2','k3','omega'):
 AA:=unapply(79-19*cos(omega*(t-3)),(t,omega));
 uss := unapply(k3*(79*k^2+79*omega^2-19*k^2*cos(omega*(t-3))-
 19*k*omega*sin(omega*(t-3)))/(k*(k^2+omega^2)),(t, k, k3, omega));
 uss0:=subs(t=0,uss);
 U:=unapply((u0-uss0)*exp(-k*t)+uss,(t,u0,k,k3,omega)):
\end{verbatim}
The two curves plus a horizontal line $u=70$ are placed onto the
\BF{plot} by this \MAPLE{} command:
\begin{verbatim}
 plot({U(t,76,0.32,0.5,Pi/12),AA(t,Pi/12),70},t=0..48);
\end{verbatim}
Missing curves? Probably, the missing curves are defined to
contain an unevaluated variable name, like \fbox{\tt pi} instead
of \fbox{\tt Pi}. While {\tt Pi} is the constant 3.14159,
lowercase symbol {\tt pi} is a variable name: {\em case} is
significant in \MAPLE{}.

Curves vanish on the printer? Add \fbox{\tt color=black} to the
plot command, e.g., \fbox{\tt plot(sin(x),x=0..Pi,color=black);}.

Click a mouse button on the high and low spots in the graphic.
Somewhere on the \MAPLE{} worksheet the coordinates of the click
are displayed (look around on the screen!). This method gives decimal
approximations to the max and min values. Use the four values obtained
to expand the list of horizontal lines to four lines. The final plot has
six curves.

The {\bf indoor temperature variation} is just the maximum of $u$ minus the
minimum of $u$, as computed from the plot of $u(t)$. The outdoor temperature variation is computed from the graph
of $A(t)$, in the same way.

The {\bf time delay} between the indoor and outdoor temperatures is
computed as $|T_2-T_1|$, where $A(T_1)=\max A(t)$ and $u(T_2)=\max
u(t)$. Look at the graphic to find sane answers for $T_1$ and $T_2$. See
the textbook for a more complete discussion of the ideas. Beware: $T_1$
and $T_2$ are values for time in the first $72$ hours (abscissa values,
not ordinate values). The smallest time delay obtainable from the
graphic is to be reported, because the transient solution $Ce^{-kt}$ may
affect the graph of $u(t)=Ce^{-kt}+u_{\mbox{ss}}(t)$ for a few hours.



\subsection*{Notes on L2.4}

A computer algebra assist for this problem uses \MAPLE{}'s
function {\tt implicitplot}. This function can plot the equation
$u(t,76,k,k3,\pi/12)=70$ over the domain $0\le t \le 72$, $0.2 \le k_1 \le
0.48$, $k=k_1+k_2$, $k_3=k_1+0.8k_2$, $k_2=0.5$. From this plot, and the 3D-plot $z=u(x,76,y,k3,\pi/12)$, the
question
is easily answered.
\begin{verbatim}
 with(plots): unassign('t','u0','k','k3','omega'):
 uh:=u0*exp(-k*t):
 up:=(the answer from L2.1):
 myANS:=uh+up:
 U:=unapply(myANS,(t,u0,k,k3,omega));k2:=0.5:
 implicitplot(U(t,76,k1+k2,k1+0.8*k2,Pi/12)=70,t=0..72,k1=0.2..0.48);
 plot3d({U(t,76,k1+k2,k1+0.8*k2,Pi/12),70},t=0..72,k1=0.2..0.48);
\end{verbatim}
The relation between the 2D implicit plot and the 3D plot is seen by
slicing the 3D plot at height $z=70$ to obtain a {\em bread slice}
parallel to the $xy$-plane. The implicit plot depicts the bread slice by
projection onto the $xy$-plane. The slice can be visualized in
\MAPLE{} by grabbing the 3D graphic with the mouse, to perform a
rotation, which exposes a view of the underside of the 3D figure. The
normal 3D view has the axes reversed, but mouse tools can be used
to orient the 3D graphic to match the 2D bread slice.

Zoom in on the implicit plot by using a smaller time domain, suggested
by the larger plot. The zoom should narrow in on a range of $k$-values
and $t$-values such that the 3D surface is entirely below the plane
$z=70$. This geometry detects sub-$70^\circ$F in the given range.

Physically, inside temperature $70$ degrees or less is reached about a hour
{\em after} the outside temperature drops low enough to generate evaporative cooler draft temperatures below $70$ degrees.
During $72$ hours, there are four such inside temperature drops,
verified from the 3D-plot, where $z$=temperature. Please report each of the four answers in this
format: {\sf
 Sub-$70^\circ$F from $0.75$ to $10.2$ hours, all $k$}.
 An answer is correct if it is supported by the graphic.

\end{document}
