\section{ Problem 3}
\subsection{Statement}
Ten days after a settlement tank is full, concentration measuments are taken various depths in the tank. The results are below. Our task is to estimate the total amount of chemical in the tank. Remember that the tank measures 18m by 5m and is 2m deep.
\begin{center}
\begin{tabular}{|c|c|}\hline
\textbf{Depth (m)}\rule{0pt}{14pt} & \textbf{Concentration (mg/L)}\\\hline
 0.0&63.5  \\
 0.25&103  \\
 0.5& 152 \\
 0.75&178  \\
 1.0& 281 \\
 1.25&303  \\
 1.5& 387 \\
 1.75&892  \\
2.0& 3120 \\\hline
\end{tabular}
\end{center}
\subsection{Estimation from the Data}
If we assume that the concentration is constant for the 25cm inbtween measurements
\begin{center}
\begin{tabular}{|c|c|r|}\hline
Concentration & Length of interval & Amount of chemical\\\hline
 63.5& 0.25  & $63.5  \times 0.25 \times 5 \times 18 \times 1000 =1.43 \times 10^{6}  $\\
 103 & 0.25&   $103   \times 0.25 \times 5 \times 18 \times 1000 =2.32 \times 10^{6}  $\\
 152 & 0.25 &  $152   \times 0.25 \times 5 \times 18 \times 1000 =3.42 \times 10^{6}  $\\
 178 & 0.25&   $178   \times 0.25 \times 5 \times 18 \times 1000 =4.01 \times 10^{6}  $\\
 281 & 0.25 &  $281   \times 0.25 \times 5 \times 18 \times 1000 =6.32 \times 10^{6}  $\\
 303 & 0.25&   $303   \times 0.25 \times 5 \times 18 \times 1000 =6.82 \times 10^{6}  $\\
 387 & 0.25 &  $387   \times 0.25 \times 5 \times 18 \times 1000 =8.71 \times 10^{6}  $\\
 892 & 0.25&   $892   \times 0.25 \times 5 \times 18 \times 1000 =20.1 \times 10^{6}  $\\
\hline							       
&&\rule{0pt}{18pt}$\dps\sum_{i=0}^{9}a_i\times dh_i\times 5\times 18\times 1\,000=53\,088\,800$\\\hline
\end{tabular}
\end{center}
Each of these multiplications can be represented as an area of a
rectangle times $18 \times 5\times 1\,000$, and together can be draw as:
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/M4_P3_1.eps}
\end{center}
Total area is 589.875. So the total amount is $  589.875\times 18\times  5\times 1\,000$, i.e.,
$53\,088\,800$.

\subsection{Improved approximations using a fitted model}
The concentration does not, however, remain constant for the whole
25cm, it changes continuously within the depths. If we had
a measurement of the concentration every 10cm we could assume
that it remained constant over these intervals, and obtain a more
accurate estimate. The closest we can get to 10cm measurements is
to fit an interpolation function to the data. Tutorialal groups from previous semesters have fitted a model of the form \[
c(h)=\frac{a}{\sqrt{b}-\sqrt{h}}
\]
to this data and found that the optimal model was:
\[
c(h)=\frac{105.5}{1.45-\sqrt{h}}
\]
So the `10cm' estimate would be $\dps
90\,000\sum_{i=0}^{19}c(0.1i)\,0.1=64\,328\,200$. To calculate this in
Mathematica we can type:
\begin{verbatim}
con[h_]=105.5138/(1.44801-Sqrt[h]);
90000*Sum[con[0.1*i]*0.1,{i,0,19}]
\end{verbatim}
The graphical representaion of this sum is 
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/M4_P3_2.eps}
\end{center}
It would be more accurate still to assume that the concentration was
constant for only 1cm, and calculate
$90\,000\sum_{i=0}^{199}0.01c(0.01i)$. The Mathematica command that does
this is \verb+90000*Sum[con[0.01*i]*0.01,{i,0,2/0.01-1}]+ and the result
is $75\,127\,900$. The illustration of this is
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/M4_P3_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}90\,000\sum_{i=0}^{2/dh-1}c(i\,dh)\,dh
\]
The Mathematica command that would calculate this is\begin{center}
\verb+Limit[90000*Sum[con[i*dh]*dh,{i,0,2/dh-1}],dh->0]+ \end{center}
Unfortunately
Mathematica can have problems calculating limits for transendental
functions, so the best we can do is to set $dh$ to a very small
value. A further problem arises because Mathematica refuses to
calculate the sum for values of $dh$ below $0.00001$. So the best
approximation we can calculate is $7.64722\times
10^7$. This is in mg so is equal to $76.4722 $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{Average Concentration}=\frac{\text{Amount}}{\text{Volume}}
\]
In this problem, however, the amount in the water changes continuously
as we go deeper down in the tank. So if we focus on the thin `sheet'
of water illustrated below
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/figures.1}
\end{center}
between the depths of $h$ and $h+dh$, we can say:
\begin{align*}
\text{\parbox{0.4\textwidth}{
\begin{center}
Average Concentration \\
between depths of\\
$h$ and  $h+dh$
\end{center}
}}&=\frac{\text{Amount of Chemical within the `sheet'}}{\text{Volume of
    water with in the `sheet'}}\\
&=\frac{A(h+dh)-A(h)}{18\times 5\times 1\,000\times dh}
\end{align*}
where we are using $A(h)$ to represent the total mass of chemical that
is contained in the top $h$m of the tank. The instantaneous concentration
at depth $h$ will, therefore be given by:
\[
c(h)=\lim_{dh\to0}\frac{A(h+dh)-A(h)}{90\,000\,dh}=\frac{1}{90\,000}\dif{A}{t}
\]
This allows to say that the differential model of the problem is:\[
\dif{A}{h}=90\,000c(h)=\frac{90\,000a}{\sqrt{b}-\sqrt{h}}
\]
To solve this equation in Mathematica we type:
\begin{verbatim}
DSolve[A'[h]==90000*bestA/(Sqrt[bestB]-Sqrt[h]),A[h],h]
\end{verbatim}
The solution that Mathematica gives is
\begin{verbatim}
C[1] + 9.496244760263806e6 
*(Sqrt[h] -2. + -2.8960278685557594 Log[-1.55876932e8 + Sqrt[h] 1.07648779e8])
\end{verbatim}
If we rephase the main question to be find the increase in the amount
from the top of the tank to the bottom, then we are asking for
$A(2)-A(0)$, and we will not have to worry about the value of the
arbitary constant \verb+C[1]+. In Mathematica we type
\verb+A[2]-A[0]+ and we get $7.64764\times10^7$.

\subsection{Final calculation}
This amount is similar, but not equal to, the amount that we estimated
as flowing into the tank. The difference in the amounts is
$7.64833\times10^7-7.64764\times10^7=6921.97$mg. This is the mass of
chemical that we estimate has been lost from the tank during the time
that the water has been settling. This may, or may not, be a large
amount, it depends on the nature of the chemical.
