\section{ Problem 2}
\subsection{Statement}
A factory needs to use a certain toxic chemical in its
processing. There is a steady flow, of 500 litres of water per hour,
through the machinary that washes the chemical into a settlement
tank. The factory runs its process for eleven hours and then stops for
one hour to allow the equipment to be washed clear of the
chemical. The table below shows the concentration of chemical in the
outlet pipe, at different times during a typical twelve hour shift.
Our task is to calculate the total mass of chemical in the tank when
it is full. The settlement tanks measure 18m by 5m and are 2m deep.
\begin{center}
\begin{tabular}{|c|c|}
\hline
\textbf{Time (Hours)} & \textbf{Concentration (mg/L)}\\\hline
0    & 0.00   \\
2    & 0.00   \\
4    & 0.28  \\
6    & 3.33   \\
8    & 100    \\
9    & 481    \\
10   & 1618     \\
10.5 & 2368     \\
11   & 2415    \\
11.5 & 1946    \\
12   & 0.00   \\
\hline
\end{tabular}
\end{center}
\subsection{Estimation from the Data}
If we assume that the concentration is constant over the time intervals
\begin{center}
\begin{tabular}{|c|c|r|}\hline
Concentration & Length of interval & Amount of chemical\\\hline
0.00& 4.0 & $ 0.00 \times 4.0 \times 500= 0.00$\\
0.28& 2.0 & $ 0.28 \times 2.0 \times 500= 0.56$\\
3.33& 2.0 & $ 3.33 \times 2.0 \times 500= 6.66$\\
100 & 1.0 & $ 100  \times 1.0 \times 500= 100$\\
481 & 1.0 & $ 481  \times 1.0 \times 500= 481$\\
1618& 0.5 & $ 1618 \times 0.5 \times 500= 809$\\
2368& 0.5 & $ 2368 \times 0.5 \times 500= 1184$\\
2415& 0.5 & $ 2415 \times 0.5 \times 500= 1207.5$\\
1946& 0.5 & $ 1946 \times 0.5 \times 500= 973$\\
\hline
&&\rule{0pt}{18pt}$\dps\sum_{i=0}^{9}a_i\times dt_i\times 500=2\,380\,860$\\\hline
\end{tabular}
\end{center}
Each of these multiplications can be represented as an area of a
rectangle times 500, and together can be draw as:
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem2/M4_P2_1.eps}
\end{center}
Total area is 4761.72. So the total amount of chemical flowing into the tank
in one shift is $ 4761.72\times  500$, i.e.,
$2\,380\,860$.

\subsection{Improved approximations using a fitted model}
The concentration does not, however, remain constant for the whole
time interval, it changes continuously within the intervals. If we had
a measurement of the concentration every 30 minutes we could assume
that it remained constant over these intervals, and obtain a more
accurate estimate. The closest we can get to 30 minute measurements is
to fit an interpolation function to the data. In Module 3 we saw a
very similar problem and using that process we see that the
concentration,$c$, at time $t$ may be written as:
\[
c(t)=18302(12-t)^2e^{1.9291(12-t)}
\]
So the `30 minute' estimate would be $\dps
500\sum_{i=0}^{23}c(0.5i)\,0.5=2\,540\,896$. To calculate this in
Mathematica we can type:
\begin{verbatim}
con[t_]=18302*(12-t)^2*E^(1.9291(12-t));
500*Sum[con[0.5*i]*0.5,{i,0,23}]
\end{verbatim}
The graphical representaion of this sum is 
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem2/M4_P2_2.eps}
\end{center}
It would be more accurate still to assume that the concentration was
constant for only 6 minutes, and calculate
$500\sum_{i=0}^{119}0.1c(0.1i)$. The Mathematica command that does
this is \verb+500*Sum[con[0.1*i]*0.1,{i,0,12/0.1-1}]+ and the result
is $2\,549\,429$. The illustration of this is
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem2/M4_P2_3.eps}
\end{center}
\subsection{Best possible approximation}
Taking this process to its limit, the best approximation we could make
by this process is 
\[
\lim_{dt\to 0}500\sum_{i=0}^{12/dt-1}c(i\,dt)\,dt
\]
The Mathematica command that would calculate this is\begin{center}
\verb+Limit[500*Sum[con[i*dt]*dt,{i,0,12/dt-1}],dt->0]+ \end{center}
Unfortunately
Mathematica can have problems calculating limits for transendental
functions, so the best we can do is to set $dt$ to a very small value,
e.g., $10^{-10}$ and calculate the sum. The answer is $2.54944\times
10^6$. This is in mg so is equal to $2.54944$kg.

\subsection{Differential Model}
If the amount of a chemical is evenly distributed through out a volume
of water then the concentration is given by the word formula
\[
\text{Concentration}=\frac{\text{Amount}}{\text{Volume}}
\]
In this problem, however, the amount in the water changes
continuously. So if we focus on a very short time interval, from $t$
to $t+dt$ say, and think about the water that leaves the outlet pipe
in this time interval, we can say:
\begin{align*}
\text{\parbox{0.4\textwidth}{
\begin{center}
Average Concentration \\
of water that passes\\
between time $t$ and time $t+dt$
\end{center}
}}&=\frac{\text{Amount of Chemical to pass
    in $dt$ hours}}{\text{Volume of
    water to pass in $dt$ hours}}\\
&=\frac{A(t+dt)-A(t)}{500\, dt}
\end{align*}
where we are using $A(t)$ to represent the total mass of chemical to have
passed through the pipe in $t$ hours. The instantaneous concentration
at time $t$ will, therefore be given by:
\[
c(t)=\lim_{dt\to0}\frac{A(t+dt)-A(t)}{500\,dt}=\frac{1}{500}\dif{A}{t}
\]
This allows to say that the differential model of the problem is:\[
\dif{A}{t}=500c(t)=500\left(18302(12-t)^2e^{1.9291(12-t)}\right)
\]
To solve this equation in Mathematica we type:
\begin{verbatim}
DSolve[A'[t]==500*(bestA*(12-t)^2*E^(bestB*(12-t))),A[t],t]
\end{verbatim}
The solution that Mathematica gives is
\begin{verbatim}
        t 1.9290836612579962
C[1] + E                     
                             2
*(t -0.010500525421595833 + t  0.00041940429675416064 + 0.06583748987344133)
\end{verbatim}
If we rephase the main question to be find the increase in the amount
to flow into the tank in a 12 hour shift, then we are asking for
$A(12)-A(0)$ and so will not have to worry about the value of the
arbitary constant \verb+C[1]+. In Mathematica we type
\verb+A[12]-A[0]+ and we get $2.54944\times10^6$.

\subsection{Final calculation}
The solution of $2.54944\times10^6$mg is the mass of chemical to flow
into the tank in one shift. To calculate the total amount to flow into
a full tank we must find out how many shifts it takes to fill a
tank. Volume of a tank is $18\times 5\times2=180$m$^3$. The total
amount of water in a full tank is, therefore $180\,000$L (a volume of
1m$^3$ holds $1\,000$L of water). The flow rate is 500L per hour so it
takes $\frac{180\,000}{500}=360$ hours to fill the tank. There are 12
hours in a shift, so it takes 30 shifts to fill a tank. Hence the
total mass of chemical to flow into the tank is
$30\times2.54944\times10^6=7.64833\times10^7$mg or 76.4833kg.