
\section{ Problem 3}
\subsection{Statement of the Problem}
A factory needs to use a certain toxic chemical in its processing. There is a steady flow of water 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.
\begin{center}
\begin{tabular}{|c|c|}
\hline
\textbf{Time (Hours)} & \textbf{Concentration (mg/L}\\\hline
0 & 0.00\\
2 & 0.00\\
4 & 0.120\\
6 & 1.42\\
8 & 42.30\\
9 & 205.00\\
10 & 690.00\\
10.5 & 1010.00\\
11 &1030.00\\
11.5 & 830.00\\
12 & 0.00\\
\hline
\end{tabular}
\end{center}
\subsection{Selecting the Model}
When plotting the data Mathematica gives a graphic of the form:
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/dataplot.eps}
\end{center}

The model that is suggested by this data is one of the form  
\[y=a(12-x)^2e^{-b(12-x)}\] 
To find the `best' values of $a$ and $b$, we will set up a total
distance funtion in a manner similar to how we proceeded for straight
line models. 
\subsection{Definition of Residuals to curves}
The next three diagrams show how the different residuals are defined\\
\vfill
\fbox{\parbox{\textwidth}{
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/figures.1}\\
Vertical Residual
\end{center}
}}\\\vfill
\fbox{\parbox{\textwidth}{
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/figures.2}\\
Horizontal Residual
\end{center}}}\\\newpage
\fbox{\parbox{\textwidth}{
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/figures.3}\\
Perpendicular Residual: The value of $\hat{x}$ is the solution of
$y_i-f(\hat{x})=f'(\hat{x})(\hat{x}-x_i)$, and the value of $\hat{y}$
is $f(\hat{x})$.
\end{center}
}}\\

Notice that in order to calculate either  horizontal or perpendicular
residuals one must first solve an equation. Consequently, these
often involve practical difficulties, and vertical residuals are often
the only ones that can be calculated.
\subsection{Misleading Residuals}
There are situations where using horizontal or vertical residuals can 
give inaccurate values to `the distance from point to curve'. These
are illustrated below.\\
\fbox{\parbox{\textwidth}{
\begin{center}
\includegraphics[height=0.3\textheight]{Problem3/figures.4}\\
Vertical residual gives an erroneously large distance.
\end{center}}}
\fbox{\parbox{\textwidth}{
\begin{center}
\includegraphics[width=0.75\textwidth]{Problem3/figures.5}\\
Horizontal residual gives an erroneously large distance.
\end{center}}}\\

Note that in both of these situations the perpendicular residual gives
a more reasonable value to `distance from point to curve', however
finding the $\hat{x}$ which satisfies
$y_i-f(\hat{x})=f'(\hat{x})(\hat{x}-x_i)$ could be difficult.
\subsection{Useful Tricks for Minimizing Total Distance Functions}
\subsubsection{Simplifying the total distance function}
The Pythagorean total distance for vertical residuals is the function:
\[
V_2(a,b)=\sqrt{(y_1-f_{(a,b)}(x_1))^2+(y_2-f_{(a,b)}(x_2))^2+\cdots+(y_n-f_{(a,b)}(x_n))^2},
\]
where $a$, and $b$ are the parameters of the model. The values of $a$
and $b$ which minimize this function will also minimize the function:
\[
V_2^2(a,b)={(y_1-f_{(a,b)}(x_1))^2+(y_2-f_{(a,b)}(x_2))^2+\cdots+(y_n-f_{(a,b)}(x_n))^2}.
\]
If this seems unlikely to you, just think about a list of positive numbers,
(e.g. $\{5,2,8,9,8,11,4\}$), take note of the position of the minimum
number, now square every number in the list
(e.g. $\{25,4,64,81,121,16\}$), and the minimum of this list is in the
same position as the minimum of the original list. Notice that this trick only works when
the function (or list of numbers) is positive.

\subsubsection{Estimating the parameters by finding an `exact fit'}
Often we can find reasonable estimates for the parameters by finding
a model that is an exact fit to a few data points. If your model has 3
parameters, say, then you should pick three of the data points that
are representative of the spread of the data, then find the parameter
values that force the model to pass exactly through these
points. These parameter values will not be the best fit for all the
data but very often they are close to the optimal values. For this
data and model, we would pick two points e.g. $(6,1.42)$ and $(11,1030)$
(avoid the points with $y$-value zero) and solve the following
equations simultaneously:\begin{align*}
1.42&=a\times 6^2\times e^{-b\times6}\\
1030&=a\times1^2\times e^{-b\times 1}
			 \end{align*}

