\input{SingleAssignmentSetup.tex}
\input{../WeekTitles.tex}
\begin{document}

\begin{center}
\subsection*{MNTC P01 - Week \#3 - \WeekTitleThree}
\end{center}

\subsection*{Taylor Polynomials}

For reference, the general formula for the Taylor polynomial centered at x = a is:
\[P(x) = f(a) + \frac{f'(a)}{1!} (x-a) + \frac{f''(a)}{2!} (x-a)^2 + ... + \frac{f^n(a)}{n!} (x-a)^n\]
where $n!$ means ``n factorial'', or $n \times (n-1) \times (n-2) \times ... 2 \times 1$.  E.g. $4! = 4 \cdot 3 \cdot 2 \cdot 1 = 24$.

\begin{enumerate}[1.]
\begin{multicols}{2}

\item
\begin{Question}
 Suppose \(g\) is a function which has continuous derivatives, and that
\(g(5)=-3, g'(5)=-2\), \(g''(5)=1\),
\(g'''(5)=-5\).
\begin{enumerate}[(a)]
\item What is the Taylor polynomial of degree 2 for \(g\) near
\(5\)?
\item What is the Taylor polynomial of degree 3 for \(g\) near
\(5\)? \\
\item Use the two polynomials that you found in parts (a) and (b) to
approximate \(g(5.1)\).
\end{enumerate}
\par  \end{Question}
\begin{Solution}

We have
\[g(x) = g(5) + g'(5)(x-5) + \frac{g''(5)}{2!}(x-5)^2
+\frac{g'''(5)}{3!}(x-5)^3+\cdots\]
Substituting gives
\[g(x) = -3  - 2(x-5) + \frac{1}{2!}(x-5)^2
  +\frac{-5}{3!}(x-5)^3+\cdots\]
  \begin{enumerate}[(a)]
\item
The degree 2 Taylor polynomial, \(P_2 (x)\), is obtained by truncating
after the \((x-5)^2\) term:
\[P_2(x) = -3+\left(-2\right)\!\left(x-5\right)+\frac{1}{2!}\cdot 1\!\left(x-5\right)^{2}.\]
\par
\item
The degree 3 Taylor polynomial, \(P_3 (x)\), is obtained by truncating
after the
\((x-5)^3\) term:
\[P_3 (x) = -3+\left(-2\right)\!\left(x-5\right)+\frac{1}{2!}\cdot 1\!\left(x-5\right)^{2}+\frac{1}{3!}\!\left(-5\right)\!\left(x-5\right)^{3}\]
\par
\item
Substitute \(x=5.1\) into the Taylor polynomial of degree 2:
\[P_2(5.1) = -3+\left(-2\right)\!\left(5.1-5\right)+\frac{1}{2!}\cdot 1\!\left(5.1-5\right)^{2} = -3.195.\]
From the Taylor polynomial of degree 3, we obtain
\begin{align*}
P_3(5.1) =&  -3+\left(-2\right)\!\left(5.1-5\right)+\frac{1}{2!}\cdot 1\!\left(5.1-5\right)^{2}+ \\
& \frac{1}{3!}\!\left(-5\right)\!\left(5.1-5\right)^{3} \\
 =& -3.19583.
\end{align*}
  \end{enumerate}
\par\end{Solution}

% ******************************
\item
\begin{Question}
  Find the Taylor polynomial of degree \(n = 4\) for \(x\) near the
  point \(a = \frac{\pi }{4}\) for the function
  \(\cos\!\left(4x\right)\).\\
  Use MATLAB to graph both the function and the Taylor polynomial on a
  reasonable interval around $x=\pi/4$.
\par  \end{Question}
\begin{Solution}

Let \(f(x)= \cos\!\left(4x\right)\). Then \(f(\frac{\pi }{4}) = -1\), and
\par\smallskip\begin{center}\begin{tabular}{|c|c|} \hline
\(f'(x) = -4\sin\!\left(4x\right)\) &\(f'(\frac{\pi }{4}) = 0\) \\ \hline
\(f''(x) = -16\cos\!\left(4x\right)\) &\(f'''(\frac{\pi }{4}) = 16\) \\ \hline
\(f'''(x) = 64\sin\!\left(4x\right)\) &\(f'''(\frac{\pi }{4}) = 0\) \\ \hline
\(f''''(x) = 256\cos\!\left(4x\right)\) &\(f''''(\frac{\pi }{4}) = -256\) \\ \hline
\end {tabular}\end{center}\par\smallskip
So,
\(P_4(x) = -1+\frac{16}{2}\!\left(x-\frac{\pi }{4}\right)^{2}+\frac{-256}{24}\!\left(x-\frac{\pi }{4}\right)^{4}\).

MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig1.m}{W03TaylorTrig1.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}
  Find the fifth order Taylor polynomial for
  \(\sin\!\left(x\right)\) near $x = \pi/4$. \\
  Use MATLAB to graph both the function and the Taylor polynomial on
  a reasonable interval around $x = \pi/4$.
  \end{Question}

\begin{Solution}
The fifth order Taylor polynomial is based on the first five derivatives of $\sin(x)$.
\begin{align*}
f(x) &= \sin(x) &  f(\pi/4) = \frac{1}{\sqrt{2}} \approx 0.7071\\
f'(x) &= \cos(x) &  f'(\pi/4) = \frac{1}{\sqrt{2}} \approx 0.7071\\
f''(x) &= -\sin(x) & f''(\pi/4) \approx -0.7071\\
f'''(x) &= - \cos(x)& f'''(\pi/4) \approx -0.7071\\
f^{(4)}(x) &= \sin(x)& f^{(4)}(\pi/4)\approx  0.7071\\
f^{(5)}(x) &= \cos(x)& f^{(5)}(\pi/4) \approx 0.7071\\
\end{align*}
Using the Taylor polynomial formula,
\begin{align*}
P_5(x) = &
\frac{1}{\sqrt{2}} +
\frac{1}{\sqrt{2}} (x-\pi/4)  -
\frac{1}{2}\frac{1}{\sqrt{2}} (x-\pi/4)^2  \\
& -
\frac{1}{3!}\frac{1}{\sqrt{2}} (x-\pi/4)^3  +
\frac{1}{4!}\frac{1}{\sqrt{2}} (x-\pi/4)^4 \\
& +
\frac{1}{5!}\frac{1}{\sqrt{2}} (x-\pi/4)^5
\end{align*}

MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig2.m}{W03TaylorTrig2.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}
 Find the Taylor polynomial of degree 3 around the point \(x = -4\) of
\(f(x) = \sqrt{5+x}\). \\
  Use MATLAB to graph both the function and the Taylor polynomial on
  a reasonable interval around the reference point.
\par  \end{Question}
\begin{Solution}

Let \(f(x) = \sqrt{5+x} = (5 +x)^{1/2}\).
\par
Then
\[f'(x) = \frac{1}{2\sqrt{5 + x}},\]
\[f''(x) = -\frac{1}{4(5 + x)^{3/2}},\]
and
\[f'''(x) = \frac{3}{8(5 + x)^{5/2}}.\]
The Taylor polynomial of degree three about \(x =-4\) is thus
\begin{align*}
P_3(x) & = \sqrt{5  - 4} + \frac{1}{2\sqrt{5 - 4}} (x  + 4 ) + (\frac{1}{2!})\,\left(-\frac{1}{4(5 - 4)^{3/2}}\right)
    (x  + 4)^2 + \\
&(\frac{1}{3!})\left(\frac{3}{8(5 - 4)^{5/2}}\right) (x  + 4)^3. \\
& = 1 + \frac{1}{2} (x+4) + \frac{1}{2!} \frac{-1}{4} (x+4)^2
+ \frac{1}{3!} \frac{3}{8} (x+4)^3
\end{align*}
MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorRoot1.m}{W03TaylorRoot1.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}

  Calculate the Taylor polynomials \(P_2(x)\) and \(P_3(x)\) centered
  at \(x = 1\) for \(f(x) = \ln\!\left(x+1\right)\). \\
  Use MATLAB to graph the function and both the Taylor polynomials on
  a reasonable interval around the reference point.
\par  \end{Question}
\begin{Solution}

Recall the general formula for the Taylor polynomial centered at \(x\) = a:
\[P(x) = f(a) + \frac{f'(a)}{1!} (x-a) + \frac{f''(a)}{2!} (x-a)^2 + ... + \frac{f^n(a)}{n!} (x-a)^n\]
\[f(x) = \ln\!\left(x+1\right)\]
\[f'(x) = \frac{1}{x+1}\]
\[f''(x) = \frac{-1}{\left(x+1\right)^{2}}\]
\[f'''(x) = \frac{2}{\left(x+1\right)^{3}}\]
So, \(f(x) = \ln\!\left(x+1\right)\) and
\(P_2(x) = A + B(x-1) + C(x-1)^2\)  \\
where  \\
\(A=f(1)=\ln (2)=0.693147\)  \\
\(B=f'(1)=\frac{1}{(2)}=0.5\)  \\
\(C=\frac{f''(1)}{2!}=-\frac{1}{(8)}=-0.125\)  \\
Thus,
\[P_2(x) = \ln (2) + \frac{1}{(2)} (x - 1)  - \frac{1}{(8)} (x - 1)^2\] \\
or,
\[P_2(x) = 0.693147+0.5\!\left(x-1\right)-0.125\!\left(x-1\right)^{2}\] \\
Similarly,  \\
\(P_3(x) = D + E(x-1) + F(x-1)^2 + G(x-1)^3\)  \\
where  \\
\(D=f(1)=\ln (2)=0.693147\)  \\
\(E=f'(1)=\frac{1}{(2)}=0.5\)  \\
\(F=\frac{f''(1)}{2!}=-\frac{1}{(8)}=-0.125\)  \\
\(G=\frac{f'''(1)}{3!}=\frac{1}{(24)}=0.0416667\)  \\
Thus,
\[P_3(x) = \ln (2) + \frac{1}{(2)} (x - 1)  - \frac{1}{(8)} (x - 1)^2 + \frac{1}{(24)}  (x - 1)^3\] \\
or,
\[P_3(x) = P_2(x)  + 0.0417 (x-1)^3\]

MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorLn1.m}{W03TaylorLn1.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}

  Calculate the Taylor polynomials \(P_2(x)\) and \(P_3(x)\) centered
  at \(x = \frac{\pi }{6}\) for \(f(x) = \sin\!\left(x\right)\). \\
Use MATLAB to graph the function and both the Taylor polynomials on a
reasonable interval around the reference point.
\end{Question}
\begin{Solution}
The 2nd and 3rd order Taylor polynomials are based on the first three derivatives of $\sin(x)$.
\begin{align*}
f(x) &= \sin(x) &  f(\pi/6) = \frac{1}{2} \\
f'(x) &= \cos(x) &  f'(\pi/6) = \frac{\sqrt{3}}{2} \approx 0.866\\
f''(x) &= -\sin(x) & f''(\pi/6) = \frac{-1}{2} \\
f'''(x) &= - \cos(x)& f'''(\pi/6) = \frac{-\sqrt{3}}{2} \approx -0.866\\
\end{align*}
Using the Taylor polynomial formula,
\begin{align*}
P_2(x) = &
\frac{1}{2} +
\frac{\sqrt{3}}{2} (x-\pi/6)  -
\frac{1}{2!}\frac{1}{2} (x-\pi/6)^2
\end{align*}
and $P_3$ will be the same, just with the cubic term added at the end.
\begin{align*}
P_3(x) = &
\frac{1}{2} +
\frac{\sqrt{3}}{2} (x-\pi/6)  -
\frac{1}{2!}\frac{1}{2} (x-\pi/6)^2   -
\frac{1}{3!}\frac{\sqrt{3}}{2} (x-\pi/6)^3
\end{align*}

MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig3.m}{W03TaylorTrig3.m}

\end{Solution}
% ******************************
\item
\begin{Question}

  Calculate the Taylor polynomials \(P_2(x)\) and \(P_3(x)\) centered
  at \(x = 7\) for \(f(x) = \frac{1}{1+x}\).  \\
  Use MATLAB to graph both the function and the Taylor polynomial on a
  reasonable interval around the reference point.
\par  \end{Question}
\begin{Solution}

\[f(x) = \frac{1}{1+x}\]
\[f'(x) = \frac{-1}{(1+x)^2}\]
\[f''(x) = \frac{2}{(1+x)^3}\]
\[f'''(x) = \frac{-6}{(1+x)^4}\]
and
\(P_2(x) = A + B(x-7) + C(x-7)^2\)  \\
where  \\
\(A=f(7)=\frac{1}{(8)}=0.125\)  \\
\(B=f'(7)=-\frac{1}{(64)}\approx-0.0156\)  \\
\(C=\frac{f''(7)}{2!}=\frac{1}{(512)}=0.00195\)  \\
Thus,
\[P_2(x) = \frac{1}{(8)}  - \frac{1}{(64)} (x - 7) + \frac{1}{(512)} (x - 7)^2\] \\
or,
\[P_2(x) = 0.125-0.0156\!\left(x-7\right)+0.00195\!\left(x-7\right)^{2}\] \\
Similarly,  \\
\(P_3(x) = D + E(x-7) + F(x-7)^2 + G(x-7)^3\)  \\
where  \\
\(D=f(7)=\frac{1}{(8)}=0.125\)  \\
\(E=f'(7)=-\frac{1}{(64)}=-0.0156\)  \\
\(F=\frac{f''(7)}{2!}=\frac{1}{(512)}=0.00195\)  \\
\(G=\frac{f'''(7)}{3!}=-\frac{1}{(4096)}=-0.000244\)  \\
Thus,
\[P_3(x) = \frac{1}{(8)}  - \frac{1}{(64)} (x - 7) + \frac{1}{(512)} (x - 7)^2  - \frac{1}{(4096)}  (x - 7)^3\] \\
or,
\[P_3(x) = P_2(x)  - 0.000244 (x-7)^3\] \\
MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorRecip1.m}{W03TaylorRecip1.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}
  Calculate the Taylor polynomials \(P_2(x)\) and \(P_3(x)\) centered
  at \(x = 2\) for \(f(x) = e^{-x}+e^{-2x}\). \\
  Use MATLAB to graph the function and both the Taylor polynomials on a
  reasonable interval around the reference point.
\end{Question}
\begin{Solution}

\[f(x) = e^{-x}+e^{-2x}\]
\[f'(x) = -e^{-x}-2e^{-2x}\]
\[f''(x) = e^{-x}+4e^{-2x}\]
\[f'''(x) = -e^{-x}-8e^{-2x}\]
and
\(P_2(x) = A + B(x-2) + C(x-2)^2\)  \\
where  \\
\(A=f(2)=e^{-2}+e^{-4}\)  \\
\(B=f'(2)=-\left(e^{-2}+2e^{-4}\right)\)  \\
\(C=\frac{f''(2)}{2!}=\frac{e^{-2}+4e^{-4}}{2}\)  \\
Thus,
\[P_2(x) = (e^{-2}+e^{-4})-\left(e^{-2}+2e^{-4}\right)\!\left(x-2\right)+\frac{e^{-2}+4e^{-4}}{2}\!\left(x-2\right)^{2}\] \\
Similarly,  \\
\(P_3(x) = D + E(x-2) + F(x-2)^2 + G(x-2)^3\)  \\
where  \\
\(D=f(2)=e^{-2}+e^{-4}\)  \\
\(E=f'(2)=-\left(e^{-2}+2e^{-4}\right)\)  \\
\(F=\frac{f''(2)}{2!}=\frac{e^{-2}+4e^{-4}}{2}\)  \\
\(G=\frac{f'''(2)}{3!}=-\frac{e^{-2}+8e^{-4}}{6}\)  \\
Thus, \(P_3(x) =\)
\[\begin{array}{lcl}
& = & e^{-2}+e^{-4}-\left(e^{-2}+2e^{-4}\right)\!\left(x-2\right)+\frac{e^{-2}+4e^{-4}}{2}\!\left(x-2\right)^{2}  \cr\cr
& & - {\frac{e^{-2}+8e^{-4}}{6}} (x-2)^3
\end{array}\]
MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorExp1.m}{W03TaylorExp1.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}

  Calculate the Taylor polynomials \(P_2(x)\) and \(P_3(x)\) centered
  at \(x = \frac{\pi }{4}\) for \(f(x) = \tan\!\left(x\right)\).

  Use MATLAB to graph the function and both the Taylor polynomials on
  a reasonable interval around the reference point.
\end{Question}
\begin{Solution}

\[f(x) = \tan\!\left(x\right)\]
\[\frac{d}{dx}\tan\!\left(x\right) = \frac{1}{\cos^{2}\!\left(x\right)}\]
\[\frac{d^2}{dx^2}\tan\!\left(x\right) = \frac{2\sin\!\left(x\right)}{\cos^{3}\!\left(x\right)}\]
\[\frac{d^3}{dx^3}\tan\!\left(x\right) = \frac{2\!\left(2\sin^{2}\!\left(x\right)+1\right)}{\cos^{4}\!\left(x\right)}\]
So, in this case,
\[P_2(x) = 1+2\!\left(x-\frac{\pi }{4}\right)+2\!\left(x-\frac{\pi }{4}\right)^{2}\]
and
\[P_3(x) = 1+2\!\left(x-\frac{\pi }{4}\right)+2\!\left(x-\frac{\pi }{4}\right)^{2} + \frac{8}{3} (x-\frac{\pi }{4})^3\]
MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig4.m}{W03TaylorTrig4.m}
\par\end{Solution}
% ******************************
\item
\begin{Question}
  Find the second-degree Taylor polynomial \(P_2(x)\) for the function
  \(f(x) = \sqrt{15+x^2}\) at the number \(x=1\).

  Use MATLAB to graph both the function and the Taylor polynomial on a
  reasonable interval around $x = \pi/4$.
\par\end{Question}
\begin{Solution}
$P_2(x)= 4+(1/4)*(x-1)+(15/(2(16)4))(x-1)^2$

MATLAB graphing: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorRoot2.m}{W03TaylorRoot2.m}
\end{Solution}
% ******************************
\item
\begin{Question}
 Find the second-degree Taylor polynomial for
\(f(x)=2 x^2 - 3 x + 8\) about
\(x=0\).
What do you notice about your polynomial?
\par  \end{Question}
\begin{Solution}

We note that \(f(0) = 8\);
\(f'(x) = 4 x - 3\), so that \(f'(0) = -3\); and
\(f''(x) = 4\), so that \(f''(0) = 4\).
\par
Thus
\[P_2(x) = 8 - 3 x + {4\over 2!} x^2
          = 8 - 3 x + 2 x^2.\]
We notice that \(f(x) = P_2(x)\) in this case, which makes
sense because \(f(x)\) is a polynomial.
\par\end{Solution}
% ******************************
\item
\begin{Question}
 Suppose that \(P_2(x)=a+bx+cx^2\) is the
second degree Taylor polynomial for the function \(f\) about \(x=0\).
What can you say about the signs of
\(a\), \(b\), \(c\) if \(f\) has the graph given below? \\
Note that the central lines are the $x$ and $y$ axes.
\begin{center}
\includegraphics[width=0.25\linewidth]{graphics/Week03_TaylorPolynomials/aableson-2281-setUnit_06_TaylorPolynomialsprob16image1}
\end{center}
\par  \end{Question}
\begin{Solution}

Since \(P_2(x)\) is the second degree Taylor polynomial for \(f(x)\)
about \(x=0\), \(P_2(0)=f(0)\), which says \(a=f(0)\).  Since
\(\frac{d}{dx}P_2(x) \big|_{x=0} = f'(0)\),
\(b=f'(0)\); and since
\(\frac{d^2}{dx^2} P_2(x) \big|_{x=0} = f''(0)\),
\(2c=f''(0)\).  In other words, \(a\) is the \(y\)-intercept of
\(f(x)\), \(b\) is the slope of the tangent line to \(f(x)\) at
\(x=0\) and \(c\) tells us the concavity of \(f(x)\) near \(x=0\).
\par
Thus
\(a < 0\); \(b > 0\); and \(c > 0\)
\par\end{Solution}
% ******************************
\item
\begin{Question}
 The function \(f(x)\) is approximated near \(x=0\) by the second
degree Taylor polynomial \(P_2(x) = 3x-3+8x^{2}\).
\par
Give values the values of $f(0)$, $f'(0)$, and $f''(0)$.
\par  \end{Question}
\begin{Solution}

Using the fact that
\[f(x)\approx
P_2(x)=f(0)+f'(0)x+\frac{f''(0)}{2!}x^2\]
and identifying coefficients with those given for \(P_2(x)\), we obtain:
\par
\(f(0)=\) the constant term, which equals \(-3\), so \(f(0)=-3\).
\(f'(0)=\) the coefficient of \(x\), which equals \(3\), so
\(f'(0)=3\).
\(\frac{f''(0)}{2!}=\) the coefficient of \(x^2\), which equals \(8\),
so \(f''(0)=16\).
\par\end{Solution}
\end{multicols}

\hrulefill

\subsection*{Optimization Introduction}
\begin{multicols}{2}

\item
\begin{Question}
Let \(f(x)=x^{2}-10x+13\), and consider the interval \([0, 10]\).
\begin{enumerate}[(a)]
\item  Find the critical point \(c\) of \(f(x)\) and compute \(f(c)\).
\item  Compute the value of \(f(x)\) at the endpoints of the interval \([0,10]\).
\item  Determine the global min and max of \(f(x)\) on \([0,10]\).
\item  Find the global min and max of \(f(x)\) on \([0,1]\). (Note: not the same interval as before)
\end{enumerate}
\par  \end{Question}
\begin{Solution}
  \begin{enumerate}[(a)]
  \item The critical point of \(f(x)\) is the solution to \(f'(x)=0\). The
  derivative is\(f'(x)=2x-10\). Setting this equal to zero and solving
  for \(x\) gives \(x=5\). Evaluating \(f(5)\) yields $-12$.
\item Evaluating \(f(0)\) and \(f(10)\), we find that each is equal to 13.
\item The global min and max values must occur at critical points or
  at the endpoints of the interval. Since the value at the critical
  point is smaller than the value at the endpoints, the value of
  \(f(5)\) is a minimum, and the value of \(f(0)\) (or \(f(10)\) since
  they are equal) is a maximum.
\item Since there are no critical points in the interval \([0,1]\), so
  the global min and max values lie at the endpoints of the
  interval. Computation yields \(f(0)=13\),\(f(1)=4\), so the minimum
  is 4 and the maximum is 13.
  \end{enumerate}
\par\end{Solution}
\item
\begin{Question}
Find the maximum and minimum values of the function \(\ds f(x)=\frac{\ln\!\left(x\right)}{x}\) on the interval [1,3].
\end{Question}
\begin{Solution}
  First we check for critical points. The critical point of \(f(x)\)
  is the solution to \(f'(x)=0\). \\
  The derivative
  is\(\ds f'(x)=x^{-2}-\frac{\ln\!\left(x\right)}{x^{2}}\). \\
  Setting this
  equal to zero and solving for \(x\) gives \(x=e^1=e\).\\
  Evaluating \(f(e)\) yields the value
  \(\frac{1}{e}=0.3679\). \\
  The values of the function at the endpoints of the interval are
  \(f(1)=0\), \(f(3)=0.3662\), so the minimum value is 0, and the
  maximum value is \(\frac{1}{e}=0.3679\).
\par
\par\end{Solution}
\item
\begin{Question}
  Find the minimum and maximum values of \(y = \sqrt{10}\theta-\sqrt{5}\sec\theta\) on the interval \([ 0, \frac {\pi}{3}]\).
\par  \end{Question}
\begin{Solution}

\par
Let \(f(\theta) = \sqrt{10} \theta - \sqrt{5}\sec \theta\).  \leavevmode\\\relax
On the interval \([ 0, \frac {\pi}{3}]\) , \(f'(\theta)= \sqrt{10} - \sqrt{5}\sec \theta \tan \theta = 0\)  at  \(\theta = \frac{\pi}{4}\).  \\
(This can be found either by inspiration, guessing that the answer is a `nice' angle like $\pi/3$, $\pi/4$ or $\pi/6$, or more mechanically by writing the whole equation in terms of $\sin(\theta)$, using $\cos^2(\theta) = 1 - \sin^2(\theta)$ and then solving a quadratic equation.) \\
The minimum value of  \(f\) on this interval is at \leavevmode\\\relax
 the endpoint \(\theta=0\), where \(f(0) = -2.2361\), \leavevmode\\\relax
whereas the maximum value over this interval is \leavevmode\\\relax
\(f(\frac{\pi}{4})=\sqrt{10}(\frac{\pi}{4} - 1) = -0.6786\). \leavevmode\\\relax
At the second endpoint \(\theta=\frac{\pi}{3}\), \leavevmode\\\relax
 \(f(\frac{\pi}{3})= \sqrt{10} \frac{\pi}{3} - 2 \sqrt{5}= -1.1606\).
\par\end{Solution}
\item
\begin{Question}

\par
Find the maximum and minimum values of the function \(\ds f(x)=x-\frac{125x}{x+5}\) on the interval [0,21].
\par  \end{Question}
\begin{Solution}

First we check for critical points. The critical point of \(f(x)\) is
the solution to \(f'(x)=0\). \\
The derivative
is\(f'(x)=1-\frac{625}{\left(x+5\right)^{2}}\). \\
Setting this equal to
zero and solving for \(x\) gives \(x=-5\pm 25\), and of these two
critical points only -5+25=20 lies in our interval.\\
 Evaluating
\(f(-5+25)=f(20)\) yields the value -80.\\
 The values of the
function at the endpoints of the interval are \(f(0)=0\),
\(f(21)=-79.9615\), so the minimum value is -80, and the maximum value
is 0.
\par
\par\end{Solution}
\item
\begin{Question}
 The function \(f(x) = -2 x^3 + 21 x^2 - 36 x + 10\)
has one local minimum and one local maximum. Find their $(x,y)$ locations.
\par\end{Question}
\begin{Solution}
  To identify any local extrema, we start by identifying critical
  points.  We note that $f(x)$ is a polynomial, so its derivative is
  defined everywhere, so only points where $f'(x) = 0$ will be
  critical points.
  \begin{align*}
    f'(x) & = -6x^2 + 42 x - 36 \\
\mbox{ Setting $f'(x) = 0$, }~~~~~~~ 0 & = -6 x^2 + 42 x - 36 \\
\mbox{ Factoring, }~~~~~~~ 0 & = -6 (x^2 - 7 x + 6) \\
0 & = -6 (x-1)(x-6)
  \end{align*}
  The two critical points are at $x=1$ and $x=6$.  Subbing those $x$
  values back into the original function $f(x)$ gives us the points
  (1, -7) and $(6, 118)$.

Using test points and the first derivative test, or taking another derivative and using the second derivative test, you can find that:  \\
there is a local minimum at (1,-7), and \\
there is a local maximum at (6, 118).

\end{Solution}
\item
\begin{Question}
 A University of Rochester student decided to depart from Earth after his
graduation to find work on Mars.  Before building a shuttle, he conducted careful
calculations.  A model for the velocity of the shuttle, from liftoff at t = 0
s until the solid rocket boosters were jettisoned at t =   80 s, is given by
\[v(t) = 0.001094333 t^3- 0.08215 t^2 + 28.6 t - 4.3\] (in feet per
second).  Using this model, estimate the global
maximum value and global minimum value of the {\bf acceleration } of
the shuttle between liftoff and the jettisoning of the boosters.
\par\end{Question}
\begin{Solution}

For simplicity of presentation, let $c_3 =  0.001094333$ and $c_2 = 0.08215$, so
$$v(t) = c_3 t^3 - c_2 t^2 + 28.6 t - 4.3$$
Differentiating once gives the acceleration
$$a(t) = 3c_3 t^2 - 2c_2 t + 28.6 $$
To find the critical points of the acceleration, we need to know when its rate of change is
zero:
$$a'(t) = 6 c_3 t - 2c_2 $$
This will have a zero value when
\begin{align*}
  0 & = 6 c_3 t - 2c_2 \\
  t & = \frac{2c_2}{6 c_3} = \frac{1}{3} \frac{0.08215}{0.001094333} \approx 25.022
\end{align*}
Thus $t \approx 25.022$ is the only critical point.

We compute the acceleration at the end points of the interval ($t=0$
and 80), and at the critical point: \\
$a(0)  = 28.6 \mbox{ ft/s}^2$ \\
$a(25.022)  = 26.5444 \mbox{ ft/s}^2$ \\
$a(80)  = 36.4672 \mbox{ ft/s}^2$ \\

The global maximum acceleration is $36.4672$ ft/s$^2$ and occurs at
$t=80$, while the global minimum acceleration is 26.5444 ft/s$^2$,
and it occurs at $t=25.022$ s.

\end{Solution}
\item
\begin{Question}
 Use the given graph of the function on the interval \((0,8]\) to answer the following questions.
\par
\begin{center}
\includegraphics[width=0.7\linewidth]{graphics/Week03_OptimizationIntro/crit_point_graph}
\end{center} \par
\begin{enumerate}[(a)]
\item Where does the function \(f\) have a local maximum?
\item Where does the function \(f\) have a local minimum?
\item What is the global maximum of \(f\)?
\item What is the global minimum of \(f\)?
\end{enumerate}
\par\end{Question}
\begin{Solution}
  \begin{enumerate}[(a)]
\item $x=$3.  ($x=8$ is an end-point, and so is {\bf not} considered a local max or min using our definitions.)
\item $x=$2, 5
\item none:  at the left end, the interval is open, so the maximum is never reached.
\item The global minimum of the function occurs at $x=5$, and the value there is $f(5) = 0$.
  \end{enumerate}

\end{Solution}
\item
\begin{Question}
 \par
Find the global maximum and minimum values of the following function on the given interval.
\par
\(f(t)= 4 t \sqrt{4-t^2}, \ [-1,2]\)
\par\end{Question}
\begin{Solution}
The global maximum occurs at $x= 1.4142$ and $y = 8$.

The global minimum occurs at $x=-1$, and $y = -6.9282$

\end{Solution}
\item
\begin{Question}
 \par
 An object with weight W is dragged along a horizontal plane by a
 force acting along a rope attached to the object. If the rope makes
 an angle \(\theta\) with the plane, then the magnitude of the force
 is
\par
$$F = \dfrac {\mu W} {\mu \sin ( \theta ) + \cos ( \theta ) }$$
\par
where \(\mu\) is a positive constant called the coefficient of
friction and where \(0 \leq \theta \leq \pi/2\). Find the value for
\(\tan \theta\) which minimizes the force. Your answer may depend on W
and \(\mu\).
\par\end{Question}
\begin{Solution}
To minimize $F$, we differentiate with respect to $\theta$:
\begin{align*}
 &&   F(\theta) & = \mu W (\mu \sin(\theta) + \cos(\theta))^{-1} \\
\mbox{ so } &&  F'(\theta) & = - \frac{\mu W}{(\mu \sin(\theta) + \cos(\theta))^2}(\mu \cos(\theta) - \sin(\theta)) \\
\end{align*}
Setting the derivative equal to zero to identify critical points,
\begin{align*}
0 & = - \frac{\mu W}{(\mu \sin(\theta) + \cos(\theta))^2}(\mu \cos(\theta) - \sin(\theta)) \\
\mbox{ requires } 0 & = (\mu \cos(\theta) - \sin(\theta)) \\
\sin(\theta) & = \mu \cos(\theta) \\
\frac{\sin(\theta)}{\cos(\theta)} & = \mu \\
\tan(\theta) & = \mu \\
\end{align*}
The question asked for the value of $\tan(\theta)$, so we have that now as $\mu$.

The greater the coefficient of friction, $\mu$, the more of our force
should be directed upwards rather than forwards, to help minimize the
friction effect.

\end{Solution}

\item
\begin{Question}
 Find the exact global maximum and minimum values of the
function \(f(t) = \frac{3 t}{8 + t^2}\) if its domain is all real
numbers.
\par  \end{Question}
\begin{Solution}

Differentiating using the quotient rule gives
\[f'(t)=\frac{3(8 + t^2) - 3 t(2 8 t)}{(8+t^2)^2} =
    \frac{3(8 - t^2)}{(8+t^2)^2}.\]
The critical points are the solutions to
\(\frac{3(8 - t^2)}{(8+t^2)^2} = 0\), which are
\(t = \pm\sqrt{8}\).
\par
Since \(f'(t)>0\) for \(-\sqrt{8}<t<\sqrt{8}\)
and \(f'(t)<0\) otherwise, there is a local
minimum at \(t=-\sqrt{8}\) and a local maximum at \(t=\sqrt{8}\).
\par
As \(t\to\pm\infty\), we have \(f(t)\to0\).  Thus, the local
maximum at \(t=\sqrt{8}\) is a global maximum of
\(f(\sqrt{8}) = {3\sqrt{8}\over 8 + 8}\),
and the local minimum at
\(t=-\sqrt{8}\) is a global minimum of
\(f(-\sqrt{8}) = {-3\sqrt{8}\over 2(8)}\).
\par\end{Solution}
\item
\begin{Question}
 A ball is thrown up on the surface of a moon.  Its height
above the lunar surface (in feet) after \(t\) seconds is given by the formula
\[h=217 t-\frac{7}{4}t^2.\]
\begin{enumerate}[(a)]
\item Find the time that the ball reaches its maximum height.
\item Find the maximal height attained by the ball.
\end{enumerate}
\par\end{Question}
\begin{Solution}
  \begin{enumerate}[(a)]
\item When the ball reaches its maximum, the velocity will be zero, so we can solve
for when velocity = $h'(t)$ = 0.

\begin{align*}
&& h'(t) & = 217 - \frac{7}{2} t \\
\mbox{ setting h'=0, } && 0 & = 217 - \frac{7}{2} t \\
&& t & = \frac{2}{7} 217 = 62 \mbox{ s}
\end{align*}
\item At the time of zero velocity, the height will be $h(62) = 6727$ m.
  \end{enumerate}
\end{Solution}
\item
\begin{Question}
 In a certain chemical reaction, substance \(A\) combines with substance
\(B\) to form substance \(Y\).  At the start of the reaction, the
quantity of \(A\) present is \(a\) grams, and the quantity of
\(B\) present is \(b\) grams.  Assume \(a<b\) and \(y\le a\).
At time \(t\)
seconds after the start of the reaction, the quantity of \(Y\)
present is \(y\) grams.  For certain types of reactions, the rate of
the reaction, in grams/sec, is given by
\[\hbox{Rate}=k(a-y)(b-y),\]
where \(k\) is a positive constant.
\begin{enumerate}[(a)]
\item Sketch a graph of the rate against \(y\).
\item For what values of \(y\) is the rate non-negative?
\item Use your graph to find the value of \(y\) at which the rate of the
reaction is fastest.
\end{enumerate}

\par  \end{Question}
\begin{Solution}

  \begin{enumerate}
\item~ \\ \includegraphics[width=0.75\linewidth]{graphics/Week03_OptimizationIntro/parabola_ab}
\par

\item If we expect the rate to be non-negative, we must have \(0\le y\le a\)
or \(b \le y\).  Since we assume \(a<b\), we restrict \(y\) to
\(0\le y\le a\).

In fact, the expression for the rate is non-negative for \(y\) greater
than $a$ but these values of \(y\) are not meaningful for the
reaction.  See the figure above (which shows the rate with \(k=1\)).
\par
\item From the graph, we see that the maximum rate occurs when \(y=0\); that
is, at the start of the reaction.
  \end{enumerate}
\par\end{Solution}
\item
\begin{Question}
  At what value(s) of \(x\) on the curve \(y = 1 + 250 x^3 - 3 x^5\)
  does the tangent line have the largest slope?
\par\end{Question}
\begin{Solution}
The slope of the tangent line is given by $y' = 750 x^2 -15 x^4$.

Consider this to be a new function, $g(x)$, that we want to maximize (to get the {\em largest} slope).  To maximize $g(x)$, we differentiate to find critical points:
\begin{align*}
  g(x) & = 750 x^2 -15 x^4 \\
\mbox{ so } g'(x) & = 1500 x - 60 x^3 \\
\mbox{ set $g'$ = 0: } 0 & = 1500 x - 60 x^3 \\
0 &= 60x (25 - x^2) \\
0 &= 60x (5 - x)(5+x) \\
x & = 0, 5, -5
\end{align*}
These are the critical points of the slope function.  To determine
which is a max, and which is a min, we can use either the first or second derivative tests.
Let's use the 2nd here because differentiation of $g'$ will be easy:
$g''(x) = 1500  - 180 x^2$ \\
$g''(-5) = -3000 < 0$: concave down; $x=-5$ is a local max. \\
$g''(0) = 1500 > 0$: concave up; $x=0$ is a local min. \\
$g''(5) = -3000 < 0$: concave down; $x=5$ is a local max. \\

The values of $g(-5) = 9375$ and $g(5) = 9375$ are the slopes of the
original function at $x=-5$ and $x=5$.  They are equal, so they are
both the common global maximum slope of $9375$.
\end{Solution}

\end{multicols}
\hrulefill

\begin{multicols}{2}

\subsection*{Optimization With MATLAB}

For Questions \ref{qoptmatlab1}-\ref{qoptmatlab2}, use MATLAB to:
\begin{itemize}
\item generate a graph of the given function on the domain shown, and
\item use the \texttt{fminbnd} function to find the global maximum and
  global minimum of the function on that interval.
\end{itemize}

% ******************************
\item \label{qoptmatlab1}
\begin{Question}
$f(x)= 7 e^{7 x^3 -  7 x} , \mbox{ on }  -1 \leq x \leq 0$
\end{Question}
\begin{Solution}

All the examples will be solved with the same basic architecture.

In the MATLAB plots,
\begin{itemize}
\item the global {\bf min} will be shown as a {\bf red} dot, and
\item the global {\bf max} will be shown as a {\bf green} dot.
\end{itemize}

If there is anything special that is required in the solving, it will
be mentioned in text, as well as a commetn in the MATLAB code.

\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptExp1.m}{W03OptExp1.m}

\lstinputlisting{MATLAB/W03OptExp1.m}

Final answer:
\begin{verbatim}
Global min (x, y)
   -0.0001    7.0032

Global max (x, y)
   -0.5774  103.5662
\end{verbatim}

\end{Solution}
% ******************************
\item
\begin{Question}
$f(x)= 7 x - 21 \ln (x),\mbox{ on } \ [1,4]$
\par\end{Question}
\begin{Solution}

  For all the following problems, we will just provide a link to the
  solution MATLAB file, and the final answer, rather than including it
  in the PDF.

  Looking at the graph, this function has a clear global max at the
  left boundary of the interval, and a global min at the critical
  point at $x=1$.

\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptLn1.m}{W03OptLn1.m}

\begin{verbatim}
Global min (x, y)
    3.0000   -2.0709

Global max (x, y)
    1.0000    6.9994
\end{verbatim}

\end{Solution}
% ******************************
\item
\begin{Question}
 \par
$f(x)= 4 e^{-x} - 4 e^{-2 x}, \mbox{ on }\ [0,1]$
\end{Question}
\begin{Solution}
  Looking at the graph, this function has a clear global max at the
  left boundary of the interval, and a global min at the critical
  point at $x\approx 0.6931$ (exact value is $x = \ln(2)$).

\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptExp2.m}{W03OptExp2.m}

Notice that MATLAB doesn't return {\em exactly} $x=0$ for the global
minimum, but just the very small
$x = 0.0661\times 10^{-3} = 0.0000661$.  This kind of slight deviation
from the exact value is common with numerical methods.

\begin{verbatim}
Global min (x, y)
   1.0e-03 *

    0.0661    0.2644

Global max (x, y)
    0.6931    1.0000
\end{verbatim}

\end{Solution}
% ******************************
\item
\begin{Question}
$f(x)= 7 x - 14 \cos (x), \mbox{ on }  [-\pi,\pi]$
\par\end{Question}
\begin{Solution}
  Looking at the graph, this function has
  \begin{itemize}
  \item a clear global max at the
  right boundary of the interval, and
\item a global min at the critical point at $x\approx -0.5236$.
  \end{itemize}

  There is a local max around $x=-2.8$ that isn't found by
  \texttt{fminbnd} when the interval is $[-\pi, pi]$.

\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptTrig1.m}{W03OptTrig1.m}

\begin{verbatim}
Global min (x, y)
   -0.5236  -15.7895

Global max (x, y)
    3.1415   35.9907
\end{verbatim}

\end{Solution}
% ******************************
\item
\begin{Question}
 \par
$f(x)= ( 3 \cos x ) / (20 + 10 \sin x ), \ 0 \leq x \leq 2 \pi$
\par\end{Question}
\begin{Solution}

  This example requires some care, as the default search with
  \texttt{fminbnd} does {\bf not} find the correct global maximum.

\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptTrig2.m}{W03OptTrig2.m}

\begin{verbatim}
Global min (x, y)
    3.6652   -0.1732

Endpoint (x, y)
    0.0001    0.1500

Global max (x, y)
    5.7596    0.1732
\end{verbatim}
\end{Solution}
% ******************************
\item\label{qoptmatlab2}
\begin{Question}
 \par
 \(f(t)=\frac{10}{t}+4, 0 < t \leq 1\)  \\
 Note the open end due to the $0 < t$ instead of $0 \le t$.
\par\end{Question}
\begin{Solution}

  {\bf Variables}: note that you can choose to change the $x$
  variables in your script to \texttt{t}, or just note that the
  function $\ds f(x) = \frac{10}{x} + 4$ has all the same properties
  as $\ds f(t) = \frac{10}{t} + 4$.

  {\bf Open Interval: }Even though we are working on an open interval,
  we can still try to use \texttt{fminbnd}.  We just need to be
  careful when running it, and interpreting its results.

\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptRecip1.m}{W03OptRecip1.m}

  If you run your \texttt{fminbnd} with $t=0$ as a boundary, you will get an error:
\begin{verbatim}
Error using fminbnd (line 219)
User supplied objective function must return a scalar value.
\end{verbatim}
  This points to the fact that $f(0)$ is actually undefined (dividing
  by zero).  As a result, the best you can do is try to use a small
  but non-zero left limit, but then check your results against the
  graph to be sure.

\begin{verbatim}
Global min (x, y)
    0.9999   14.0005

Global max (x, y)
   1.0e+04 *

    0.0000    6.0209
\end{verbatim}
  {\bf However}, the global max is actually incorrect.  This function won't have a global max,
  because there is a vertical asymptote at $t=0$, so there is no single highest point for this function.

\end{Solution}

\end{multicols}
\hrulefill
\subsection*{Optimization Word Problems}

\begin{multicols}{2}

% ******************************
\item
\begin{Question}
 Some airlines have restrictions on the size of items of luggage that
passengers are allowed to take with them.  Suppose that one has a rule
that the sum of the length, width and height of any piece of luggage
must be less than or equal to 192 cm.  A passenger wants to take a
box of the maximum allowable volume.
\begin{enumerate}[(a)]
\item If the length and width are to
be equal, what should the dimensions be?
\item In this case, what is the volume?
\item If the length is be twice the width, what should the dimensions be?
\item In this case, what is the volume?
\end{enumerate}
Include units in all your answers.
\par  \end{Question}
\begin{Solution}

  Let the length, width and height of the box be \(L\), \(w\) and
  \(h\), respectively.  Then the volume of the box is \(V = Lwh\).
  The sum \(L + w + h = 192\), and, for the first part, we know that
  \(L = w\).  Thus \(2w + h = 192\), so \(h = 192 - 2w\), and the
  volume equation becomes \(V = Lwh = w\cdot w\cdot(192 - 2w) =
  192\cdot w^2 - 2w^3\).  Since we need $h \ge 0$ and $h = 192 - 2w$,
  the domain for \(w\) is \(0\le w\le 96\).
\par
Critical points are where
\(\frac{dV}{dw} = 2\cdot 192\cdot w - 6\cdot w^2 = 0\), so
\(w = 0\) or \(w = 64\).  The global maximum must occur either at
this point or at the end points.  \(V(64) > 0\) while
\(V(0) = V(96) = 0\), so the global maximum is at \(L=w=64\),
in which case \(h=64\) as well.  The volume is then
\(V = 64^3 = 262144 {\rm cm}^3\).
\par
If \(L = 2w\), \(2w + w + h = 192\), so
\(V = (2w)(w)(192 - 3w) = 384 w^2 - 6 w^3\).  Proceeding as
before, we find \(w = \frac{128}{3}\), \(L = \frac{256}{3}\) and \(h = 64\), so that
\(V = \frac{2097152}{9}\).
\par\end{Solution}
% ******************************
\item
\begin{Question}
 A wire 3 meters long is cut into two pieces.  One piece is bent
into a square for a frame for a stained glass ornament, while the
other piece is bent into a circle for a TV antenna.
\begin{enumerate}[(a)]
\item To reduce storage
space, where should the wire be cut to {\bf minimize} the total area of both
figures?
\item Where should the wire be cut to {\bf maximize} the total area?
\end{enumerate}
\par  \end{Question}
\begin{Solution}
  \begin{enumerate}[(a)]
  \item Note that we are interested in {\it the total area enclosed by
the two figures} .  Our first task is therefore to find an
equation for this area, which will be the sum of the areas of the two
figures.
\par
Suppose we cut \(x\) meters of wire to make the circular antenna.
Then there are \(3 - x\) meters left for the square.  To find the
area of the circle we need its radius.  The circumference of a circle
of radius \(r\) is \(C = 2\pi r\), so the radius of the circle is
given by \(2\pi r = x\), and so \(r = \frac{x}{2\pi}\).  The area
of the circular antenna is therefore
\(A_c = \pi r^2 = \frac{1}{4\pi} x^2\).
\par
Then the perimeter of a square with side length \(s\) is
\(P = 4 s = 3 - x\), so the side length is
\(s = \frac{1}{4}(3 - x)\).  Then the area of a square is
\(A_s =  s^2\), so the area of the square is
\(A_s =  (\frac{1}{16})(3 - x)^2\).
\par
The total area is therefore
\[A = \frac{1}{4\pi} x^2 +  (\frac{1}{16})(3 - x)^2
  = \frac{1}{4\pi} x^2 + \frac{1}{ (16)}(9 - 6 x + x^2).\]
The domain for \(x\) is \(0\le x\le 3\).
\par
The maximum and minimum of \(A\) will occur at critical or end
points.  Critical points are where \(dA/dx = 0\), or, where
\[\frac{1}{2\pi} x + \frac{1}{ (16)}(2x - 6) = 0.\]
Collecting all terms in \(x\) we have
\[\left( \frac{1}{2\pi} + \frac{2 }{ (16)}\right) x =
  \frac{6 }{16},\]
so, after simplifying,
\[x = \frac{3 \pi}{4 + \pi}.\]
\par
To determine if this is a local maximum or minimum, we use the second
derivative test.
\[A'' = \left( \frac{1}{2\pi} + \frac{2 }{ (16)}\right) > 0,\]
so the function is concave up everywhere and this is a local minimum.
Also, because this is the {\em only} critical point, this is also a {\em global}
minimum for the area.

Thus to minimize area we use \(\frac{3 \pi}{4 + \pi}\) meters of wire
for the circle and \(3 - \frac{3 \pi}{4 + \pi}\) meters for the
square.
\item To {\em maximize} the area, we can't use our critical point,
  which was a minimum; instead we must use the endpoints.  The areas
  at the endpoints are
\[A(0) = \frac{9}{16} \approx 0.56\qquad{\rm and}\qquad
   A(3) = \frac{9}{4\pi} \approx 0.72,\]
the larger of which is \(A(3)\), so the maximum area occurs when
all of the wire is used for the circle and none for the square.
  \end{enumerate}
\par\end{Solution}
% ******************************
\item
\begin{Question}
 A printed poster is to have a total area of 799 square inches with top and
bottom margins of 6 inches and side margins of 4 inches. What should be the
dimensions of the poster so that the printed area be as large as possible?
Let \(x\) denote the width of the poster and let \(y\)
denote the length.

\includegraphics[width=0.7\linewidth]{graphics/Week03_OptimizationWordProblems/Poster}

\begin{enumerate}[(a)]
\item Write the function of $x$ and $y$ that you need to maximize.
\item Express that function in terms of $x$ alone.
\item Find the critical points of the function.
\item Use the second derivative test to verify that \(f(x)\) has a maximum at this critical point
\item Find the optimal dimensions of the poster, and the resulting area.  Include units.
\end{enumerate}
\par\end{Question}
\begin{Solution}
  \begin{enumerate}[(a)]

\item $\mbox{Area} = A = (x-2\cdot 4 )(y - 2\cdot 6)= (x - 8)(y - 12)$
\item By using the requirement that $799 = x y$, we get  $A = (x - 8)(799/x - 12)$
\item Differentiating and setting the derivative equal to zero, we obtain $x = 23.08$.
\item The second derivative of $A$ will be negative at $x = 23.08$, so
  $A$ is concave down there, indicating $x=23.08$ is a local maximum for the printed area.
\item The dimensions of the poster with the largest printed area will be
$23.08 \times 34.62$, with a net printed area of 341.09 cm.
  \end{enumerate}

\end{Solution}
% ******************************
\item
\begin{Question}
 A box with an open top has vertical sides, a square bottom, and a volume of
32 cubic meters. If the box has the least possible surface area, find its
dimensions.
\par\end{Question}
\begin{Solution}
This is the same question studied in the course videos.  Let the dimensions
of the box be $w$ and $h$; the bottom is square so $w$ can represent the length of both
sides of the bottom.  These combine to produce
$$A = w^2 + 2(wh) + 2(wh), ~~~~ V = w^2h = 32$$
Solving for $h$ in the $V$ equation, $\ds h = 32/w^2$, we can write
$A$ as just a function of $w$:
\begin{align*}
A & = w^2 + 4w(32/w^2) \\
A & = w^2 + 128/w \\
\end{align*}
Differentiating and setting $A' = 0$, you will find $w = 4$, and consequently $h = 32/w^2 = 2$.

\end{Solution}
% ******************************
\item
\begin{Question}
 Find the dimensions of the rectangle of largest area that can be
inscribed in an equilateral triangle with sides of length 2 if
one side of the rectangle lies on the base of the triangle.
\par\end{Question}
\begin{Solution}
The optimal rectangle will be 1 unit on the base, and have height $\ds \frac{\sqrt{3}}{2}$.

\end{Solution}
% ******************************
\item
\begin{Question}
 Find the minimum distance from the parabola
 \[x - y^2 = 0\]  to the point {(0,3)}.
\par\end{Question}
\begin{Solution}

The point of closest approach will occur at $y=1$, and that will give a distance
of $\sqrt{ 1^2 + (3-1)^2} = \sqrt{5}$.
\end{Solution}
% ******************************
\item
\begin{Question}
  I have enough pure silver to coat \(2\) square meters of surface
  area.  I plan to coat a sphere and a cube.
  \begin{enumerate}[(a)]
  \item Allowing for the possibility of all the silver going onto one
    of the solids, what dimensions should they be if the total volume
    of the silvered solids is to be a maximum?
  \item Now allowing for the possibility of all the silver going onto
    one of the solids, what dimensions should they be if the total
    volume of the silvered solids is to be a minimum?
  \end{enumerate}
\par  \end{Question}
\begin{Solution}

  Let \(s\) be the length of the cube, \(A\) the total area, and \(V\)
  the total volume.  Then
\[A=4\pi r^2+6s^2\]
and
\[V= \frac{4}{3}\pi r^3 + s^3.\]
Obviously, the volume is maximized if we put all of our stock in the
sphere.  In that case,
\[r = \sqrt{\frac{A}{4\pi}} \approx 0.3989\hbox{~meters}\]
(and \(s=0\) meters).
To minimize the volume we eliminate one of the variables and find a
stationary point as usual.
Solving the area equation for \(s\) gives
\[s= \sqrt{\frac{A-4\pi r^2}{6}}.\] Substituting this value in the
volume equation gives
\[V= \frac{4}{3}\pi r^3 + \left(\frac{A-4 \pi
r^2}{6}\right)^{\frac{3}{2}}.\]
Differentiating with respect to \(r\) and setting to zero gives:
\[V'=4\pi r^2 - \frac{3}{2}\times\frac{8\pi r}{6} \left(\frac{A-4 \pi
r^2}{6}\right)^{\frac{1}{2}} = 0.\]
This simplifies to
\[2r = \sqrt{\frac{A-4 \pi
r^2}{6}}.\]
Squaring gives
\[4r^2 = \frac{A-4 \pi
r^2}{6}\]
which gives
\[r = \sqrt{\frac{A}{24+4\pi}} \approx  0.2339\hbox{~meters.}\]
The corresponding value of \(s\) is
\[s = 2r = \sqrt{\frac{A}{6+\pi}} \approx  0.4677\hbox{~meters.}\]
\par\end{Solution}
% ******************************
\item
\begin{Question}
Suppose that 241 ft of fencing are used to enclose a corral in the shape of a rectangle with a semicircle whose diameter is a side of the rectangle as the following figure:\leavevmode\\\relax
\includegraphics[width=0.3\linewidth]{graphics/Week03_OptimizationWordProblems/WindowShape}

Find the dimensions of the corral with maximum area.
\par  \end{Question}
\begin{Solution}

\par
From the picture, we see that \(x\) is the width of the corral, and therefore the diameter of the semicircle, \leavevmode\\\relax  and that \(y\) is the height of the rectangular section. Thus the perimeter of the corral can be expressed \leavevmode\\\relax
by the equation \(2y+ x+ \frac{\pi}{2}x= 2y + (1+ \frac{\pi}{2})x= 241\) ft or equivalently, \leavevmode\\\relax
\(y=\frac{1}{2}(241 - (1+ \frac{\pi}{2})x)\). Since \(x\) and \(y\) must both be non-negative, it follows that \(x\) must \leavevmode\\\relax
be restricted to the interval \([0, \frac{241}{1+ \pi/2}]\). The area of the corral is the sum of the area of the \leavevmode\\\relax
rectangle and semicircle, \(A= xy + \frac{\pi}{8}x^2\). Making the substitution for \(y\) from the \leavevmode\\\relax
constraint equation, \par
\(A(x)=\frac{1}{2}x(241 - (1+ \frac{\pi}{2})x) + \frac{\pi}{8}x^2 = 120.5 x - \frac{1}{2}(1+ \frac{\pi}{2})x^2 + \frac{\pi}{8}x^2\). \leavevmode\\\relax
Now, \(A'(x) = 120.5 - (1 + \frac{\pi}{2})x + \frac{\pi}{4}x = 0\) implies \(x= \frac{120.5}{(1+ \frac{\pi}{4})} \approx 67.4919\).  \leavevmode\\\relax
With \(A(0)=0\), \par
\(A(\frac{120.5}{(1+ \frac{\pi}{4})}) \approx 4066.39 \qquad\) and \(\qquad A(\frac{241}{1+ \frac{\pi}{2}}) \approx 3451.11\), \leavevmode\\\relax
it follows that the corral of maximum area has dimensions \par
\(x= \frac{120.5}{1+ \frac{\pi}{4}} \qquad\) and \\
\(\qquad y= \frac{1}{2}(241 - (1+ \frac{\pi}{2}) \frac{120.5}{1+ \frac{\pi}{4}}) \approx 33.746\).
\par\end{Solution}
% \item
% \begin{Question}

% \par
% Find the maximum area of a triangle formed in the first quadrant by the \(x\)-axis, \(y\)-axis and a tangent line to the graph of \(f=(x + 2)^{-2}\).
% \par  \end{Question}
% \begin{Solution}

% Let \(P\left(t,\frac{1}{(t+2)^2}\right)\) be a point on the graph of the curve \(y=\frac{1}{(x+2)^2}\) in the first quadrant. The tangent line to the curve at \(P\) is
% \[L(x)=\frac{1}{(t+2)^2}-\frac{2(x-t)}{(t+2)^3},\]
% which has \(x\)-intercept \(a=\frac{3t+2}{2}\) and \(y\)-intercept \(b=\frac{3t+2}{(t+2)^3}\). The area of the triangle in question is
% \[A(t) = \frac{1}{2}ab = \frac{(3t+2)^2}{4(t+2)^3}.\]
% Solve
% \[A'(t) = \frac{(3t+2)(3\cdot 2-3t)}{4(t+2)^4} = 0\]
% for \(0 \le t\) to obtain \(t = 2\).  Because \(A(0) = \frac{1}{4 \cdot 2}\), \(A(2) = \frac{1}{2 \cdot 2}\) and \(A(t) \to 0\) as \(t \to \infty\), it follows that the maximum area is \(A(2) = 0.25\).
% \par\end{Solution}
\item
\begin{Question}

\par
A box is constructed out of two different types of metal. The metal for
the top and bottom, which are both square, costs \$4 per square foot
and the metal for the sides costs \$6 per square foot. Find the
dimensions that minimize cost if the box has a volume of 35 cubic
feet.
\par  \end{Question}
\begin{Solution}

Let \(x>0\) be the length of a side of the square base and \(z>0\) the height of the box. With volume \(x^{2} z=35\), we have \(z=35/x^{2}\) and cost
\[C(x)=4\cdot 2\cdot x^{2}+6\cdot 4\cdot xz=8x^{2}+840\frac{1}{x}.\]
Solve \(C'(x)=8\cdot 2x-840x^{-2}=0\) to obtain \(x= \left(\frac{35 \cdot 6}{4} \right)^{1/3}\).
Since \(C(x) \to \infty\) as \(x \to 0+\) and as \(x \to \infty\), the minimum cost is
\(C\left( (\frac{35 \cdot 6}{4})^{1/3} \right)
\approx \$ 336.499\)
when
\(x\approx 3.74444\textrm{ ft}\)
and
\(z\approx 2.49629\textrm{ ft}\).
\par\end{Solution}
%\item
%\begin{Question}
% A manufacturer has been selling 1550 television sets a week at \$540
% each.  A market survey indicates that for each \$23 rebate offered to
% a buyer, the number of sets sold will increase by 230 per week.
% \begin{enumerate}[(a)]
% \item Find the price, $p(x)$, as a function of $x$, where \(x\) is
%   the number of the television sets sold per week.
% \item How large rebate should the company offer to a buyer, in order
%   to maximize its revenue?
% \item If the weekly cost function is \(139500 + 180 x\), how should
%   it set the size of the rebate to maximize its profit?
% \end{enumerate}
%\par\end{Question}
%\begin{Solution}
% \begin{enumerate}[(a)]
%\item $p(x) = (1550-x)/10 +540$.
%\item Revenue = price $\times$ demand = $(540 - 23\cdot x) (1550-x)/10 +540$.
%Finding the critical point of the revenue function, you will find $x = 192.5$.
%\item Build profit as revenue - cost. Compute the critical points, and
% you will find $x= 102.5$ produces a maximum profit.
% \end{enumerate}
%
%\end{Solution}
% \item
% \begin{Question}
%   A baseball team plays in he stadium that holds 72000
%   spectators. With the ticket price at 12 the average attendence has
%   been 30000. When the price dropped to 11, the averege attendence
%   rose to 36000.  \leavevmode\\\relax
%   \begin{enumerate}[(a)]
%   \item Find the demand function \(p(x)\), where \(x\) is the number
%     of the spectators. (assume \(p(x)\) is linear.)
%   \item How should be set a ticket price to maximize revenue?
%   \end{enumerate}
% \par\end{Question}
% \begin{Solution}
%  {
% \vspace{-\parskip}\begin{itemize}
% \item $(30000-x)*1/(6*1000) +12$
% \item 8.5
% \end{itemize}}\par
%\end{Solution}
%\item
%\begin{Question}
% For the cost function \(C(x) = 40000+800 x + x^2\) find:
% \begin{enumerate}[(a)]
%\item The cost at the production level 1650.
%\item The average cost at the production level 1650.
%\item The marginal cost at the production level 1650 (this is the in.
%\item The production level that will minimize the average cost.
%\item The minimal average cost.
% \end{enumerate}
%\par\end{Question}
%\begin{Solution}
%  \begin{enumerate}[(a)]
%\item 4082500
%\item 2474.24242424242
%\item 4100
%\item 200
%\item 1200
%  \end{enumerate}
%
%\end{Solution}
% \item
% \begin{Question}
%   A rectangle is inscribed with its base on the \(x\) axis and its
%   upper corners on the parabola \(y= 12 - x^2\).  What are the
%   dimensions of such a rectangle with the greatest possible area?
% \par  \end{Question}
% \begin{Solution}

% To solve this problem, we need to find an expression for the area of the
% rectangle in terms of one of its dimensions, and then use derivatives to
% maximize this area.  First, however, we can simply things quite a bit by
% noting that the parabola given by \(y = 12 - x^2\) is symmetric about
% the \(y\)-axis.  Therefore, the inscribed rectangle will also be symmetric
% about the \(y\)-axis.  So it is enough to find the dimensions of half of this
% rectangle and double the x value.
% \par
% Our rectangle will therefore have the bottom left corner \((0,0)\) and the top
% right corner \((x,12-x^2)\) where \(x\) is the width of the rectangle,
% and \(12 - x^2\) is its height.  Thus, the area of the rectangle is
% given by \(f(x) = x(12-x^2) = {12}x-x^3\) where \(x\) is the width
% of the rectangle.  We now find the derivative of this and solve for zero
% to find critical points.
% \par
% The derivative is \(f'(x) = 12 - 3x^2\).  Setting this equal to 0 and
% recalling that we are talking about widths, so that all \(x\) values
% should be positive, we get:
% \par
% \[\begin{aligned}
%     f'(x) & = 0 \\
%     12 - 3x^2 & = 0 \\
%     3x^2 & = 12 \\
%      x^2 & = \frac{12}{3} = 4 \\
%      x & = \sqrt{4} = 2
%   \end{aligned}\]
% \par
% It is easy to check that the second derivative of \(f(x)\) is negative everywhere,
% so this is a maximum of \(f(x)\).  Therefore, this is the width of the rectangle with the
% maximum area. Actually, it is the width of half of that rectangle, since we were
% ignoring the half on the left side of the y-axis. So the width of the whole rectangle is \(2\cdot 2 =  4\).  The height is given by
% plugging \(x=2\) into the formula for the parabola, giving
% \(12 - (2)^2  = 12 - 4 = 8 \).
% \par\end{Solution}
\item
\begin{Question}
 Centerville is the headquarters of Greedy Cablevision Inc. The
cable company is about to expand service to two nearby towns,
Springfield and Shelbyville.  There needs to be cable connecting
Centerville to both towns.  The idea is to save on the cost of
cable by arranging the cable in a Y-shaped configuration.
Centerville is located at
\((8,0)\) in the \(xy\)-plane, Springfield is at \((0,5)\), and
Shelbyville is at \((0,- 5)\). The cable runs from Centerville
to some point \((x,0)\) on the \(x\)-axis where it splits into two branches going to
Springfield and Shelbyville. Find the location \((x,0)\)
that will minimize the amount of cable between the 3 towns and
compute the amount of cable needed. Justify your answer.
\par
\begin{enumerate}[(a)]
\item What function of $x$ needs to be minimized to solve this problem?
\item Find the critical points of $f(x)$.
\item Use the second derivative test to verify that \(f(x)\) has a minimum at this critical point.
\item Compute the minimum amount of wire needed.
\end{enumerate}
\par\end{Question}
\begin{Solution}
  \begin{enumerate}[(a)]
\item Draw a sketch.   \\
\includegraphics[width=0.7\linewidth]{graphics/Week03_OptimizationWordProblems/Cablevision}

With $x$ being the horizontal component of the diagonal lines, the
total length of the cable will be $L(x) = 2 \sqrt{x^2+5^2}+(8 -x)$.
\item Taking the derivative and finding critical points of $L(x)$ yields $x = 2.89$.
\item The second derivative of $L(x)$ will be positive at $x = 2.89$, indicating that
the critical point is a local minimum for the length of cable.
\item $L(2.89) = 2 \sqrt{(2.89)^2 + 25} + (8-2.89) = 16.66$ units of cable.
  \end{enumerate}

\end{Solution}
\item
\begin{Question}
  A cylinder is inscribed in a right circular cone of height 4 m and
  radius (at the base) equal to 3.5 m.  What are the dimensions of
  such a cylinder which has maximum volume?
\par  \end{Question}
\begin{Solution}

As we are attempting to maximize the volume of the inscribed cylinder,
we must first come up with a formula for the volume of this cylinder.
Let \(x\) be the radius of the cylinder, \(v(x)\) the volume.  We
know from basic geometry that the formula for volume is give by
\(\pi x^2h\) where \(x\) is the radius and \(h\) is the height
of the cylinder.  So in order to come up with a formula for volume
in terms of \(x\) only, we need to relate \(x\) to \(h\).
\par
This is where the information about the cone comes in handy.  The cone is
a right circular cone.  Thus, inscribing the cylinder will fill up
some of the base of the cone, and just touch the slanted side, leaving
a similar right circular cone at the top.  This new cone will have a
radius of \(x\) and a height of \(4 - h\) where \(x\) and \(h\) are as in the formula for the volume of our cylinder.  As this cone is
similar to the original, we can use ratios to get:
\par
\[\frac{x}{3.5}=\frac{4 - h}{4}\]
\par
Simplifying this, we get \(h = 4 - \frac{4}{3.5}x\).
Therefore, our formula for volume in terms of \(x\) becomes \(v(x) = \pi
x^2(4 - \frac{4}{3.5}x) = (4\pi)x^2 -
(\frac{4}{3.5}\pi)x^3\)
\par
Now, we want to maximize this.  So we will first take the derivative.
Using the rules for differentiation of polynomials, the derivative is \(v'(x) = 2(4\pi)x - 3(\frac{4}{3.5}\pi)x^2\).  Solving
for zero, we get, as we don't want \(x = 0\), the following.
\par
\[\begin{aligned}
      v'(x)  & = 0 \\
      2(4\pi)x - 3(\frac{4}{3.5}\pi)x^2 & = 0 \\
      \pi x(2(4) - 3\frac{4}{3.5}x) & = 0 \\
      2(4) - 3\frac{4}{3.5}x & = 0 \\
      3\frac{4}{3.5}x & = 2(4) \\
      x & = \frac{2}{3}(3.5) = 2.333 \mbox{ m}\\
    \end{aligned}\]
Then, using the formula for height we came up with before, the height
can be determined by:
\[h = 4 - \frac{4}{3.5}(2.333) = 1.333\mbox{ m}\]
\par\end{Solution}
% \item
% \begin{Question}
%  A small island is 3 miles from the nearest point P on the straight
% shoreline of a large lake.  If a woman on the island can row a boat
% 2 miles per hour and can walk 3 miles per hour, where should
% the boat be landed in order to arrive at a town 8 miles down the
% shore from P in the least time?  Let \(x\) be the distance (in miles) between
% point P and where the boat lands on the lakeshore.
% \begin{enumerate}[(a)]
% \item Enter a function \(T(x)\) that describes the total amount of
% time the trip takes as a function of the distance \(x\).
% \item What is the distance \(x = c\) that minimizes the travel time?
% \item What is the least travel time?
% \end{enumerate}
% \end{Question}
% \begin{Solution}
% See the similar example in the course notes.
% \begin{enumerate}[(a)]
% \item \begin{align*}
% T(x)&  =
% \frac{\mbox{water dist}}{\mbox{water speed}} +
% \frac{\mbox{land dist}}{\mbox{land speed}} \\
% & = \frac{\sqrt{9+x^2}}{2}+\frac{(8-x)}{3}
% \end{align*}
% \item The minimum of $T(x)$ will occur when $x = 2.68$ miles.
% \item For that landing point, the travel time will be $T(2.68) = 3.78$
%   hours or about 3 hours and 45 minutes.
% \end{enumerate}
%
%\end{Solution}

\end{multicols}

\end{enumerate}
\end{document}


\chapter{Interpolation of the data}
\label{Sec:interpolate}
The data in \xendl\ representing the probability density
$\pi(E', \mu \mid E ) = \pi_r(E', \mu \mid E )$ in the integrals (\ref{Inum}) and~(\ref{Ien})
are given in various forms.  In the case of tabulated data, intermediate
values must be obtained via some sort of interpolation.  Interpolation
with respect to one independent variable is described first, followed by a discussion of
the 2-dimensional case.  In \xendl\ full 3-dimensional interpolation
of $\pi(E', \mu \mid E )$ data is reduced to a sequence of 2-dimensional
interpolations.

\section{Interpolation methods for a single variable}\label{Sec:1d-interp}
For the sake of having a specific application,
the discussion here is given in terms of tables of data $\{E_i, f(E_i)\}$,
with values $E_i$ of the energy of the outgoing particle as independent variable.
These ideas are applicable to one dimension for any tabular data.
The types of interpolation method used in \xendl\
for such tables are: histogram, linear-linear,
log-linear, linear-log, and log-log.  The algorithms for interpolation
of $F(E)$ on an interval $E_0 < E < E_1$ with given $f(E_0)$ and~$f(E_1)$
are as follows.  In these definitions it is assumed that the argument of a
logarithm is positive.

\subsection{Histograms}
For histogram interpolation set
$$
  f(E) = f(E_0) \quad \text{for $E_0 \le E < E_1$}.
$$

\subsection{Linear-linear}
 For linear-linear interpolation set
\begin{equation}
   \alpha = \frac{E - E_0}{E_1 - E_0}
 \label{def-alpha}
\end{equation}
and take
$$
  f(E) = (1 - \alpha)f(E_0) + \alpha f(E_1)
   \quad \text{for $E_0 \le E \le E_1$}.
$$

\subsection{Log-linear}
For log-linear interpolation take $\alpha$ as in Eq.~(\ref{def-alpha}),
and set
$$
 \log f(E) = (1 - \alpha)\log f(E_0) + \alpha \log f(E_1)
   \quad \text{for $E_0 \le E \le E_1$}.
$$
This relation may also be written as
\begin{equation}
  f(E) = f(E_0)^{1 - \alpha} f(E_1)^\alpha.
 \label{loglin-interp}
\end{equation}

\subsection{Linear-log}
 For linear-log interpolation set
\begin{equation}
   \alpha' = \frac{\log(E / E_0)}{\log( E_1 / E_0 )}
 \label{def-alpha-prime}
\end{equation}
and take
$$
  f(E) = (1 - \alpha')f(E_0) + \alpha' f(E_1)
   \quad \text{for $E_0 \le E \le E_1$}.
$$

\subsection{Log-log}
For log-log interpolation take $\alpha'$ as in Eq.~(\ref{def-alpha-prime}),
and set
$$
 \log f(E) = (1 - \alpha')\log f(E_0) + \alpha' \log f(E_1)
   \quad \text{for $E_0 \le E \le E_1$}.
$$
This is equivalent to
\begin{equation}
  f(E) = f(E_0)^{1 - \alpha'} f(E_1)^{\alpha'}.
 \label{loglog-interp}
\end{equation}

\textbf{Remark.}
With log-linear interpolation written in the form of Eq.~(\ref{loglin-interp})
and log-log interpolation written as Eq.~(\ref{loglog-interp}), it is permitted
that $f(E_0) = 0$ or $f(E_1) = 0$.  These cases all lead to the result that
$f(E) = 0$ for $E_0 < E < E_1$, however.

\section{Interpolation methods for probability densities}\label{Sec:2d-interp}
In order to explain the methods for interpolation of probability densities, it suffices to
consider a table of values $\pi( E' \mid E )$
\begin{equation}
  \{ E'_{j,k}, \pi(E'_{j,k} \mid E_k )\} \quad \text{for $j = 0$, 1, $\ldots\,$, $J_k$}
  \label{EPtable}
\end{equation}
given at values of the incident energy~$E_k$, for
$k = 0$,~1, $\ldots\,$,~$K$.
In Eq.~(\ref{EPtable}) it is required that the outgoing energies
be ordered
\begin{equation}
  E'_{0,k} < E'_{1,k} \le E'_{2,k} \le \cdots \le E'_{J_k-1,k} < E'_{J_k,k}.
  \label{Eout-order}
\end{equation}

The condition Eq.~(\ref{Eout-order}) permits the data of
Eq.~(\ref{EPtable}) to have equal consecutive intermediate
outgoing energies $E'_{j-1,k} = E'_{j,k}$, so that the probability
density~$\pi(E' \mid E_k)$ may have a jump discontinuity there.
Jump discontinuities are not allowed at the end points $E' = E'_{0,k}$
and~$E' = E'_{J_k,k}$.  In Eq.~(\ref{EPtable}) the possibility
of three or more consecutive equal outgoing energies may be ruled out,
because all but the first and last would be redundant.
The convention adopted here is that the value of $\pi(E' \mid E_k)$
at a discontinuity is the second data value
$$
 \pi(E' \mid E_k) = \pi(E'_{j,k} \mid E_k) \quad
  \text{if $E' = E'_{j-1,k} = E'_{j,k}$.}
$$

For fixed incident energy $E_k$, the rules for interpolation of
$\pi(E' \mid E_k )$ in outgoing energy~$E'$ are as given
in Section~\ref{Sec:1d-interp}.  The following types
of interpolation with respect to $E$ are discussed in subsequent subsections:
\begin{enumerate}
 \item direct interpolation.
 \item unit-base interpolation,
 \item interpolation using cumulative points.
\end{enumerate}

The method referred to here as ``interpolation by cumulative points''
is closely related to ``interpolation by corresponding energies'' as described
in the \ENDF\ manual~\cite{ENDFB}.
For a more-detailed discussion of 2-dimensional interpolation methods,
see the reference~\cite{interpolation}.

For a discussion of interpolation of data Eq.~(\ref{EPtable}), it suffices
to consider interpolation between incident energies $E_0$ and~$E_1$.
Thus, it is desired to interpolate to incident energy~$E$ with
$E_0 < E < E_1$ the data
\begin{equation}
\begin{split}
  \{ E'_{j,0}, \pi(E'_{j,0} \mid E_0 )\} &\quad \text{for $j = 0$, 1, $\ldots\,$, $J_0$}, \\
  \{ E'_{j,1}, \pi(E'_{j,1} \mid E_1 )\} &\quad \text{for $j = 0$, 1, $\ldots\,$, $J_1$}.
  \label{EPtables}
\end{split}
\end{equation}
The ideas presented apply equally well to interpolation of data
in Eq.~(\ref{EPtable}) between any consecutive pair of
incident energies $E_{k-1} < E_k$.

The methods of 2-dimensional interpolation are described in turn.
For each of these methods the interpolated probability density $\pi(E' \mid E)$
for $E_0 < E < E_1$ has the proper norm
\begin{equation}
  \int
  \pi(E' \mid E) \ dE' = 1
  \label{piNorm}
\end{equation}
when the interpolation rule with respect to incident energy~$E$ for the
data Eq.~\eqref{EPtables} is linear-linear, histogram, or linear-log.
The norm condition Eq.~\eqref{piNorm} is not usually satisfied when
log-linear or log-log interpolation is used for the incident energy.

\subsection{Direct interpolation}\label{Sec:direct-interp}
It is common to do direct interpolation for interpolating tables of angular probability
density~$\pi( \mu \mid E)$ with respect to incident energy~$E$, because the
range of direction cosines is usually $-1 \le \mu \le 1$.  For example, in order
to determine the value of $\pi( \mu \mid E)$ for $E_0 < E < E_1$ from data
Eq.~(\ref{EPtables}), one first interpolates in $\mu$
at fixed incident energies to obtain $\pi( \mu \mid E_0)$ and~$\pi( \mu \mid E_1)$.
One then obtains the value of $\pi( \mu \mid E)$ by interpolating between
$\pi( \mu \mid E_0)$ and~$\pi( \mu \mid E_1)$.

The trouble with the application of direct interpolation to tables of
energy distributions
 is that the range of outgoing energy~$E'$
usually depends on the incident energy~$E$.
Thus, for the data in Eq.~(\ref{EPtables}), the ranges of outgoing energies
are given by
\begin{equation}
\begin{split}
  \Eminzero' =  E'_{0,0} \quad \text{and} \quad
           \Emaxzero' = E'_{J_0,0} \quad \text{for $E = E_0$}, \\
  \Eminone' =  E'_{0,1} \quad \text{and} \quad
           \Emaxone' = E'_{J_1,1} \quad \text{for $E = E_1$}.
  \label{Eout-ranges}
\end{split}
\end{equation}

\textbf{Remark.}
In the definition of the range of outgoing energies Eq.~(\ref{Eout-ranges}),
it is natural to expect that the data in Eq.~(\ref{EPtables}) are such that
for each incident energy $E_k$ with $k = 0,$~1, $\ldots\,$,~$K$, the probability
density $\pi(E' \mid E_k )$ is not equal to zero on the entire lowest outgoing
energy range $E'_{0,k} < E' < E'_{1,k}$ or highest outgoing energy range
$E'_{J_k - 1,k} < E' < E'_{J_k,k}$.  That is,
Eq.~(\ref{Eout-ranges}) ought to give the
actual range of outgoing energies.
Some nuclear data libraries, e.~g.,
\ENDFdata~\cite{ENDFdata}, have
data of the form Eq.~(\ref{EPtable}) which imply that
$\pi(E' \mid E_k ) = 0$ on the lowest or highest outgoing energy ranges.
The sample input data given in
Section~\ref{Sec:isotropic-table-lab} illustrates the problem.

It is convenient to describe the process of direct interpolation using
notation of set theory, with the sets
\begin{equation}
\begin{split}
  \calA_0 = \{ E': \Eminzero' \le E' \le
           \Emaxzero' \}, \\
  \calA_1 = \{ E':   \Eminone' \le E' \le
           \Emaxone' \}.
  \label{def-calA01}
\end{split}
\end{equation}
The union of these two sets is denoted by
\begin{equation}
   \calA_X = \calA_0 \cup \calA_1,
 \label{def-calA-X}
\end{equation}
and the intersection is denoted by
\begin{equation}
   \calA_T = \calA_0 \cap \calA_1,
 \label{def-calA-T}
\end{equation}

There are two obvious interpretations of direct interpolation of
the data in Eq.~(\ref{EPtables}) when the outgoing energy ranges
differ, $\calA_0 \ne \calA_1$.  One may do \textit{direct interpolation
with extrapolation} or \textit{direct interpolation
with truncation}.   Linear-linear versions of these methods are
described here.

For direct interpolation with extrapolation the probability densities
$\pi(E' \mid E_0 )$ and $\pi(E' \mid E_1 )$ constructed from the
tables in Eq.~(\ref{EPtables})  are extrapolated to
\begin{equation}
  \pi_X(E' \mid E_0 ) = \begin{cases}
    \pi(E' \mid E_0 ) &\quad \text{for $E'$ in $\calA_0$,} \\
    0 &\quad \text{for $E'$ in $\calA_X \setminus \calA_0$,}
  \end{cases}
  \label{def-pi-X0}
\end{equation}
and
\begin{equation}
  \pi_X(E' \mid E_1 ) = \begin{cases}
    \pi(E' \mid E_1 ) &\quad \text{for $E'$ in $\calA_1$,} \\
    0 &\quad \text{for $E'$ in $\calA_X \setminus \calA_1$.}
  \end{cases}
  \label{def-pi-X1}
\end{equation}
For direct interpolation
to incident energy $E$ with $E_0 < E < E_1$,
the proportionality factor $q$ is  defined as
\begin{equation}
  q = \frac{ E - E_0}{ E_1 - E_0 }.
  \label{def-q}
\end{equation}
In linear-linear direct interpolation with extrapolation,
the interpolant is taken to be
\begin{equation}
  \pi_X(E' \mid E ) = ( 1 - q )\, \pi_X(E' \mid E_0 ) + q\, \pi_X(E' \mid E_1 )
  \label{def-pi-X}
\end{equation}
for $E'$ in the set~$\calA_X$.

The method of direct interpolation with truncation differs from
that using extrapolation, in that this method uses the truncated
probability densities
\begin{equation}
 \begin{split}
   \pi_T(E' \mid E_0 )& = C_0 \pi(E' \mid E_0 ), \\
   \pi_T(E' \mid E_1 )& = C_1 \pi(E' \mid E_1 )
  \end{split}
 \label{def-pi-T01}
\end{equation}
for outgoing energy $E'$ in the set~$\calA_T$.  Here, $C_0$
and~$C_1$ are normalization constants such that
$$
   \int_{\calA_T} dE' \, \pi_T(E' \mid E_0 ) = 1
   \quad \text{and} \quad
   \int_{\calA_T} dE' \, \pi_T(E' \mid E_1 ) = 1.
$$
For linear-linear direct interpolation with truncation of the data in Eq.~(\ref{EPtables})
to incident energy $E$ with $E_0 < E < E_1$, the factor~$q$
is chosen as in Eq.~(\ref{def-q}), and the interpolant is
$$
  \pi_T(E' \mid E ) = ( 1 - q )\, \pi_T(E' \mid E_0 ) + q\, \pi_T(E' \mid E_1 )
$$
for $E'$ in the set~$\calA_T$.

\textbf{Remarks.}
The \ENDFdata\ data~\cite{ENDFdata} contains many instances in which
linear-linear direct interpolation is specified, but the \ENDF\ manual~\cite{ENDFB}
says nothing about how to deal with differences in range of outgoing
energies.  Both versions can be expected to produce violation of
energy conservation.  The {\gettransfer} code
currently uses direct interpolation with extrapolation.

\subsection{Unit-base interpolation}\label{Sec:unitBase}
Only the linear-linear version of unit-base interpolation is discussed here.
The first step in unit-base interpolation is the construction of the
range of energies of the outgoing particle.
The minimum and maximum
outgoing energies for the data in Eq.~(\ref{EPtables})
are given by Eq.~(\ref{Eout-ranges}).
For incident energy~$E$ with $E_0 < E < E_1$, the factor~$q$
is taken as in Eq.~(\ref{def-q}), and
 the minimum and maximum outgoing energies
are given by
\begin{equation}
 \begin{split}
   \Emin'& = ( 1 - q )\Eminzero' + q \Eminone', \\
   \Emax' & = ( 1 - q )\Emaxzero' + q \Emaxone'.
  \label{EoutRange}
 \end{split}
\end{equation}

The interpolated probability density $\pi(E' \mid E)$ must
satisfy the normalization condition
\begin{equation}
  \int_{\Emin'}^{\Emax'} dE' \, \pi(E' \mid E) = 1.
 \label{probabilityNorm}
\end{equation}
One way to ensure this is to first map the outgoing energy ranges
Eq.~(\ref{Eout-ranges}) to unit base $0 \le \Ehat' \le 1$
and to scale the probability densities Eq.~(\ref{EPtables})
accordingly.  Thus, for the data in Eq.~(\ref{EPtables}) at
incident energy~$E_0$, set
\begin{equation}
  \Ehat' = \frac{ E' - \Eminzero'}{ \Emaxzero' - \Eminzero'}
  \label{unit-base-map}
\end{equation}
and scale the probability density
\begin{equation}
  \pihat(\Ehat' \mid E_0) = ( \Emaxzero' - \Eminzero' )\pi(E' \mid E_0).
  \label{unitbaseMap}
\end{equation}
For incident energy $E_1$, the outgoing energy is scaled
as
\begin{equation}
    \Ehat' = \frac{ E' - \Eminone'}{ \Emaxone' - \Eminone'},
  \label{unit-base-map1}
\end{equation}
and the probability density
is scaled to define the unit-base probability
density
\begin{equation}
  \pihat(\Ehat' \mid E_1) = ( \Emaxone' - \Eminone' )\pi(E' \mid E_1)
  \label{unitbaseMap1}
\end{equation}
for $0 \le \Ehat' \le 1$.

If linear-linear interpolation with respect to incident energy is
desired, the proportionality factor $q$ defined in
Eq.~(\ref{def-q}) is used to linearly interpolate between
$\pihat(\Ehat' \mid E_0)$ and $\pihat(\Ehat' \mid E_1)$
by setting
\begin{equation}
  \pihat(\Ehat' \mid E) = (1 - q)\,\pihat(\Ehat' \mid E_0) +
   q \,\pihat(\Ehat' \mid E_1)
 \label{unitbaseInterp}
\end{equation}
for $0 \le \Ehat' \le 1$.

Finally, in order to define the interpolated probability
density $\pi(E' \mid E)$, invert the mappings Eq.~(\ref{unit-base-map})
and~Eq.~(\ref{unitbaseMap}).  Specifically, with $\Emin'$ and
$\Emax'$ as in Eq.~(\ref{EoutRange}), set
\begin{equation}
   E' = \Emin' + ( \Emax' - \Emin')\Ehat'
 \label{range-inv}
\end{equation}
and take
\begin{equation}
  \pi(E' \mid E) = \frac{\pihat(\Ehat' \mid E)}{ \Emax' - \Emin' }.
 \label{unitbaseInvert}
\end{equation}

Unit-base interpolation is ordinarily not used with tables of
angular probability densities~$\pi( \mu \mid E)$, because the
range of direction cosines is usually~$-1 \le \mu \le 1$.  One
may want to use it for a table with forward emission given in
the laboratory frame, however.

\subsection{Interpolation by cumulative points}\label{Sec:cumProb}
The method of interpolation by cumulative points that is
used in the code \gettransfer\ is proposed in~\cite{interpolation},
and it is a modification of interpolation by corresponding energies as described
in the \ENDF\ manual~\cite{ENDFB}.
Interpolation by corresponding energies requires the selection of
$N$ equiprobable energy bins, so the result depends on the value of~$N$.
It is shown in~\cite{interpolation} that for data Eq.~(\ref{EPtable}) which are
histograms with respect to outgoing energy $E'$, interpolation by cumulative
points is equivalent to interpolation by corresponding energies with~$N = \infty$.
The \gettransfer\ code therefore uses interpolation by cumulative points
whenever the data specify interpolation by corresponding energies.

One objection to unit-base interpolation is that the mapping
(\ref{unitbaseMap}) depends only
on the range of outgoing energies.
One can often get a better approximation to the physics if the
interpolation method incorporates
knowledge of the local behavior of each $\pi( E' \mid E_k)$
in Eq.~(\ref{EPtable}).
One method of doing so is based on the cumulative
probability function
\begin{equation}
  \Pi( E' \mid E_k) = \int_{E'_{k,\text{min}}}^{E'} dx\, \pi( x \mid E_k)
  \label{cumProb}
\end{equation}
for $k = 0$,~1, $\ldots\,$,~$K$.

Because the data $\pi( E' \mid E_k)$ consist of probability densities,
it follows that $\pi( E' \mid E_k) \ge 0$.  Hence, $\pi( E' \mid E_k)$
s a non-decreasing function of~$E'$.  There are
energy distributions in the data library
\xendl~\cite{GND} for which $\pi( E' \mid E_k ) = 0$
on an interval $E_{j - 1,k}' < E' < E_{j,k}$ for $k = 0$~or~1
and for some values of $j = 1$, 2, $\ldots\,$, $J_k$.
The corresponding cumulative probability is constant
on such intervals.  The method of cumulative points
depends on solutions of the equation
$$
  \Pi(E' \mid E_k ) = Y
$$
for given value of  $0 \le Y \le 1$.  Denote the
largest solution by
$$
  S = \max \left \{ E': \Pi(E' \mid E_k ) = Y \right \}
$$
and the smallest solution by
$$
  T = \min \left \{ E': \Pi(E' \mid E_k ) = Y \right \}.
$$
If $\pi( E' \mid E_k ) = 0$ only at discrete
points, then $\Pi(E' \mid E_k )$ is strictly increasing
and $S = T$.

The cumulative points method is defined as
follows.
\begin{enumerate}
\item For probability density data Eqs.~\eqref{EPtables}
at incident energy~$E_k$ with $k = 0$ and~1, compute the cumulative
probabilities $\Pi( E' \mid E_k )$ in Eqs.~\eqref{cumProb}
at the data points~$E_{j,k}'$ for $j = 0$, 1, $\ldots\,$, $J_k$.
Denote the result as
\begin{equation}
  y_{j,k} = \Pi( E_{j,k}' \mid E_k ).
 \label{def-phijk}
\end{equation}
\item Form the union of these two sets
\begin{equation}
   \{Y_\ell\} = \{y_{j,0}\} \cup \{y_{j,1}\},
 \label{def-Phi-cup}
\end{equation}
remove duplicates, and arrange the remaining values
in increasing order,
\begin{equation}
  0 = Y_0 < Y_1 < \cdots < Y_L = 1.
 \label{Phi-ordered}
\end{equation}
\item For $k = 0$ and~1 and for each $Y = Y_\ell$ with
$\ell = 1$, 2, $\ldots\,$, $L$,
compute the outgoing energies
$S_{\ell,k}'$ and~$T_{\ell,k}'$ by solving the equations
\begin{equation}
 \begin{split}
     S_{\ell,k}' &= \max \left \{ E': \Pi(E' \mid E_k ) = Y_{\ell-1} \right \}, \\
      T_{\ell,k}' &= \min \left \{ E': \Pi(E' \mid E_k ) = Y_\ell \right \}.
 \end{split}
  \label{T-cum-prob-inv}
\end{equation}
\item For $k = 0$ and~1 form the intervals $\calB_\ell(E_k)$
\begin{equation}
 \begin{split}
   \calB_\ell(E_k) &= \{E' : S_{\ell,k}' \le E' < T_{\ell,k}' \}
     \quad \text{for $\ell = 1$,~2, $\ldots\,$,~$L-1$,} \\
   \calB_L(E_k) &= \{E' : S_{L,k}' \le E' \le T_{L,k}' \}.
 \end{split}
  \label{def-B-ell}
\end{equation}
The reason for omitting right-hand endpoints of
intervals $\calB_\ell(E_k)$ for $\ell < L$ in Eqs.~\eqref{def-B-ell}
is that they may be points of discontinuity
of the original energy distributions in Eq.~\eqref{EPtables}.
\item For incident energy $E$ with $E_0 < E < E_1$ do unit-base
interpolation of $\pi( E' \mid E_0 )$ on $\calB_\ell(E_0)$ with
$\pi( E' \mid E_1 )$ on $\calB_\ell(E_1)$
for $\ell = 1$,~2, $\ldots\,$,~$L$. The interpolation with
respect to~$E$ may be histogram, linear-linear, or linear-log.
The linear-linear version is as follows.
For $k = 0$ and~1 use
\begin{equation}
  \Ehat' = \frac{ E' -  S_{\ell,k}'}{  T_{\ell,k}' -  S_{\ell,k}'}
  \label{unit-base-map-cum}
\end{equation}
to map the interval $\calB_\ell(E_k)$
to $0 \le \Ehat' < 1$ for $\ell = 1$,~2, $\ldots\,$,~$L-1$ and to
$0 \le \Ehat' \le 1$ for $\ell = L$.  Scale the probability density
accordingly,
\begin{equation}
  \pihat(\Ehat' \mid E_k) = (T_{\ell,k}' -S_{\ell,k}' )\pi(E' \mid E_0).
  \label{unit-base-scale}
\end{equation}
Define the proportionality factor
\begin{equation}
  \alpha = \frac{ E - E_0 }{ E_1 - E_0 }
  \label{def-alpha-cum}
\end{equation}
and interpolate to obtain
\begin{equation}
  \pihat(\Ehat' \mid E) = (1 - \alpha)\pihat(\Ehat' \mid E_0) +
   \alpha \pihat(\Ehat' \mid E_1)
 \label{unitbaseInterpCum}
\end{equation}
for $0 \le \Ehat' < 1$ and $\ell < L$ and for $0 \le \Ehat' \le 1$ and $\ell = L$.
For $\ell = 1$,~2, $\ldots\,$,~$L$
interpolate the end points of the intervals $\calB_\ell(E_k)$ to
obtain
\begin{equation}
 \begin{split}
  S_{\ell,\alpha}' &= (1 - \alpha)S_{\ell,0}' + \alpha S_{\ell,1}', \\
  T_{\ell,\alpha}' &= (1 - \alpha)T_{\ell,0}' + \alpha T_{\ell,1}'.
 \end{split}
  \label{energy-range}
\end{equation}
At incident energy~$E$
the range of outgoing energies~$E'$ as taken as
\begin{equation}
 \begin{split}
   \calB_\ell(E) &= \{E' : S_{\ell,\alpha}' \le E' < T_{\ell,\alpha}' \}
     \quad \text{for $\ell = 1$,~2, $\ldots\,$,~$L-1$,} \\
   \calB_L(E) &= \{E' : S_{L,\alpha}' \le E' \le T_{L,\alpha}' \}.
 \end{split}
  \label{def-B-ell-alpha}
\end{equation}
Finally, the interpolated probability
density $\pi( E' \mid E )$ is obtained by inversion of the mapping
Eq.~\eqref{unit-base-scale}, giving
\begin{equation}
  \pi(E' \mid E) = \frac{\pihat(\Ehat' \mid E)}{  T_{\ell,\alpha}' -  S_{\ell,\alpha}'}
 \label{map-inv}
\end{equation}
for $E'$ in $\calB_\ell(E)$.
Set $\pi(E' \mid E) = 0$ for all outgoing energies~$E'$ which
are not in any of the sets $\calB_\ell(E)$ for
$\ell = 1$,~2, $\ldots\,$,~$L$.
\end{enumerate}

For tables of angular probability densities~$\pi( \mu \mid E)$, direct interpolation
is often used for interpolating with respect to incident energy~$E$,
because the direction cosines usually range over $-1 \le \mu \le 1$.
For angular distributions with strong local features, interpolation by cumulative points
may be preferable.

\subsubsection{Practical considerations: intervals of zero length}
\label{Sec:cum-points-trivial}
Experience with interpolation
by cumulative points as described above shows that it must be
modified to deal with the inaccuracy of
computer arithmetic.  In particular, it may happen that
for $k=0$ or~1 and for some $\ell = \widehat \ell$
the values of $S'_{ \ell,k}$ and~$T'_{ \ell,k}$
as obtained from Eq.~(\ref{T-cum-prob-inv}) are computed to be equal.
The mapping Eq.~(\ref{unit-base-map-cum}) to unit base is then undefined.

This phenomenon may be understood in terms of the computer's
machine epsilon, which is the smallest number $\epsilon_{\text{mach}}$
such that $1 + \epsilon_{\text{mach}} > 1$ in the computer's arithmetic.
In double precision arithmetic a common value is
$$
  \epsilon_{\text{mach}}  = 2^{-52} \approx 2.22 \times 10^{-16}.
$$
In particular, if the exact values of $S_{\widehat \ell,k}' $ and $T_{\widehat \ell,k}' $
are such that $S_{\widehat \ell,k}' > 0$ and
$$
  T_{\widehat \ell,k}'  - S_{\widehat \ell,k}'  < \epsilon_{\text{mach}} S_{\widehat \ell,k}',
$$
then the computer will say that $S_{\widehat \ell,k}' = T_{\widehat \ell,k}'$.

Consider first the case that the probability density $\pi(E' \mid E_k )$ is
given as a histogram.  Then in exact arithmetic the cumulative points algorithm
ensures the existence of $S_{\widehat \ell,k}' $ and $T_{\widehat \ell,k}' $
such that
\begin{equation}
  \Pi(S_{\widehat \ell,k}' \mid E_k ) = Y_{\widehat \ell-1}
  \quad \text{and} \quad
  \Pi(T_{\widehat \ell,k}' \mid E_k ) = Y_{\widehat \ell}.
 \label{get-S-T}
\end{equation}
Furthermore, it is assured that $S_{\widehat \ell,k}'  < T_{\widehat \ell,k}' $
and that
$$
  \pi(E' \mid E_k ) = \pi_{\widehat \ell,k}
  \quad \text{for} \quad
  S_{\widehat \ell,k}' \le E' < T_{\widehat \ell,k}',
$$
where $\pi_{\widehat \ell,k}$  is a positive constant.  Thus, if it happens
that
\begin{equation}
  Y_{\widehat \ell} - Y_{\widehat \ell-1} <
  \epsilon_{\text{mach}}  \pi_{\widehat \ell,k} S_{\widehat \ell,k}' ,
 \label{bad-cum-prob}
\end{equation}
the computer will conclude that $S_{\widehat \ell,k}' = T_{\widehat \ell,k}'$.
Because of the factor $\pi_{\widehat \ell,k}$ appearing on the right-hand
side of Eq.~{\ref{bad-cum-prob}), this phenomenon is usually associated
with narrow resonances in the data.  The size of $ \pi_{\widehat \ell,k}$ depends
on the units used for energy, but the product $ \pi_{\widehat \ell,k} S_{\widehat \ell,k}' $
is dimensionless, and it is typically large at a resonance.  For example,
for $S_{\widehat \ell,k}'  = 1\,\text{MeV}$ the value $ \pi_{\widehat \ell,k}
= 1.0 \times 10^8\,\text{MeV}^{-1}$ is reasonable, and Eq.~(\ref{bad-cum-prob})
could easily be satisfied.

The situation for a piecewise linear probability density $\pi(E' \mid E_k )$ is
a little different.  For one thing, the value $ \pi_{\widehat \ell,k}$ in
Eq.~(\ref{bad-cum-prob}) is replaced by the average
$$
  \frac{1}{2} \left(
    \pi( S_{\widehat \ell,k}' \mid E_k ) +  \pi( T_{\widehat \ell,k}' \mid E_k )
  \right).
$$
Another difference from the histogram case is that the determination of
$S_{\widehat \ell,k}' $ and $T_{\widehat \ell,k}' $ in Eq.~(\ref{get-S-T})
require the solution of quadratic equations, with additional inaccuracy
introduced by the computer arithmetic.

This raises the question of what to do when the solution of
Eq.~(\ref{T-cum-prob-inv}) gives values of $S_{ \widehat \ell,k}'$ and
$T_{\widehat \ell,k}'$
which are nearly equal for some $\widehat \ell$ and~$k$.
The first requirement is a definition of equality for computer arithmetic.
In the \gettransfer\ code $S'_{ \widehat \ell,k}$ and~$T'_{ \widehat \ell,k}$
are considered to be essentially equal if
\begin{equation}
  \left|
    S'_{ \widehat \ell,k} - T'_{ \widehat \ell,k}
  \right| <
  \frac{ \delta_r} {2} \left(
    S'_{ \widehat \ell,k} + T'_{ \widehat \ell,k}
  \right),
 \label{bad-unit-base}
\end{equation}
where $\delta_r$ is the parameter \texttt{tight\_tol}
described in Section~\ref{Sec:floatingPoint}.

 The decision on what to do in \gettransfer\ about such near equality of
$S'_{ \widehat \ell,k}$ and~$T'_{ \widehat \ell,k}$  is based on the size of
$Y_{\widehat \ell} - Y_{\widehat \ell-1}$.  Let $\delta_c$
be the parameter \texttt{cum\_prob\_skip} described in
Section~\ref{Sec:cum-prob-skip}.
If Eq~(\ref{bad-unit-base})
is satisfied and
\begin{equation}
  Y_{\widehat \ell} - Y_{\widehat \ell-1} < \delta_c,
 \label{drop-B-ell}
\end{equation}
then the sets $\calB_{\widehat \ell}(E_k)$ with $k = 0$,~1
in Eq.~(\ref{def-B-ell}) are omitted from the computation of the
transfer matrix.  This omission introduces an error of at most one part
in~$1/\delta_c$ in the transfer matrix.

On the other hand, if Eq~(\ref{bad-unit-base})
is satisfied and Eq~(\ref{drop-B-ell}) is violated for some
$\widehat \ell$ and~$k$, then in \gettransfer\ the interval
$\calB_{\widehat \ell}(E_k)$ is reduced to the point
\begin{equation}
   \calB_{\widehat \ell}(E_k) = \{E' : E' = \widetilde S_{\widehat \ell,k}' \}
  \label{def-B-ell-point}
\end{equation}
with
\begin{equation}
    \widetilde S_{\widehat \ell,k}' =
     \frac{ 1} {2} \left(
    S'_{ \widehat \ell,k} + T'_{ \widehat \ell,k}
  \right),
  \label{def-S-ell-point}
\end{equation}
and $\pi( E' \mid E_k )$ on $\calB_{\widehat \ell}(E_k)$ is taken
to be a delta function
\begin{equation}
  \pi( E' \mid E_k ) = \left(
    Y_{\widehat \ell} - Y_{\widehat \ell - 1}
   \right)
  \delta( E' - \widetilde S_{\widehat \ell,k}'  ).
 \label{delta-data}
\end{equation}
Note that in exact arithmetic the intervals $\calB_{\ell}( E_k )$ defined
in Eq.~(\ref{def-B-ell}) are disjoint.  For the construction here,
however, there is no guarantee that the point $\calB_{\widehat \ell}(E_k)$
obtained from Eqs.~(\ref{def-B-ell-point}) and~(\ref{def-S-ell-point})
is not contained in $\calB_{\widehat \ell - 1}( E_k )$ or~$\calB_{\widehat \ell + 1}( E_k )$.

If it happens that the delta function Eq.~(\ref{delta-data}) is used
for both $k = 0$ and $k = 1$, then for incident energy~$E$ with
$E_0 < E < E_1$, the set  $\calB_{\widehat \ell}(E)$ in
Eq.~(\ref{def-B-ell-alpha}) is defined as the single point
$$
  \widetilde S_{\widehat \ell, \alpha}' = ( 1 - \alpha ) \widetilde S_{\widehat \ell, 0}' +
  \alpha \widetilde S_{\widehat \ell,1}'
$$
with $\alpha$ given by Eq.~(\ref{def-alpha-cum}).  The
probability density on $\calB_{\widehat \ell}(E)$ is taken to be
the delta function
$$
   \pi( E' \mid E ) = \left(
    Y_{\widehat \ell} - Y_{\widehat \ell - 1}
   \right)
  \delta( E' - \widetilde S_{\widehat \ell, \alpha}'  ).
$$

It remains to consider the case when Eq~(\ref{bad-unit-base})
is satisfied and Eq~(\ref{drop-B-ell}) is false for only one value
of~$k$, say $k = 0$.  In that case the set $ \calB_{\widehat \ell}(E_0)$
reduces to a point as in Eqs.~(\ref{def-B-ell-point}) and~(\ref{def-S-ell-point}), and
$\pi( E' \mid E_0 )$ on  $ \calB_{\widehat \ell}(E_0)$ is defined to be as
in Eq.~(\ref{delta-data}) with $k = 0$.  For the mapping of this
$\pi( E' \mid E_0 )$ on  $ \calB_{\widehat \ell}(E_0)$ to unit base,
Eq.~(\ref{unit-base-scale}) is replaced by in \gettransfer\ by
$$
  \pihat(\Ehat' \mid E_0) = Y_{\widehat \ell} - Y_{\widehat \ell - 1}
  \quad \text{for} \quad
  0 \le \Ehat'  \le 1.
$$
At incident energy~$E$ with $E_0 < E < E_1$ the interpolation
Eq.~(\ref{unitbaseInterpCum}) is performed using $\alpha$
defined by Eq.~(\ref{def-B-ell-alpha}).  For inversion of the
unit base map at incident energy~$E$, the range of outgoing
energies Eq.~(\ref{energy-range}) is replaced by
\begin{equation*}
 \begin{split}
  S_{\ell,\alpha}' &= (1 - \alpha) \widetilde S_{\widehat \ell, 0}'  + \alpha S_{\ell,1}', \\
  T_{\ell,\alpha}' &= (1 - \alpha) \widetilde S_{\widehat \ell, 0}'  + \alpha T_{\ell,1}'.
 \end{split}
  %\label
\end{equation*}
The probability density $\pi( E' \mid E )$ for $S_{\ell,\alpha}' \le E' <
T_{\ell,\alpha}'$ is then calculated using the scaling Eq.~(\ref{map-inv}).

\section{Unscaled interpolation of Kalbach-Mann data}\label{Sec:Kalbach-r-interp}
The above discussion pertains to the interpolation of tables of probability densities,
for which maintenance of the norm condition Eq.~(\ref{probabilityNorm})
is essential.  The parameter~$r(\Ecm', E)$ in Eq.~(\ref{Kalbach-eta}) for the
Kalbach-Mann model of double-differential data is given as tables
depending on the energy $E$ of the incident particle and the energy $\Ecm'$ of
the outgoing particle in the center-of-mass frame, and it has the different
constraint,
\begin{equation}
  0 \le r \le 1.
 \label{Kalbach-r-constraint}
\end{equation}

Again, it suffices to describe interpolation between Kalbach-Mann $r$
data between tables at incident energies $E_0$ and~$E_1$ with
$E_0 < E_1$.  As in Eq.~(\ref{def-calA01}),
consider the sets $\calA_0$ of outgoing energies
at $E = E_0$ and $\calA_1$ at $E = E_1$.  For unscaled direct interpolation
with extrapolation, take $\calA_X = \calA_0 \cup \calA_1$ as in
Eq.~(\ref{def-calA-X}), so that the extrapolated $r$ parameter is
\begin{equation*}
  r_X(E', E_0 ) = \begin{cases}
    r(E', E_0 ) &\quad \text{for $E'$ in $\calA_0$,} \\
    0 &\quad \text{for $E'$ in $\calA_X \setminus \calA_0$,}
  \end{cases}
%  \label{def-r-X0}
\end{equation*}
and
\begin{equation*}
  r_X(E', E_1 ) = \begin{cases}
    r(E', E_1 ) &\quad \text{for $E'$ in $\calA_1$,} \\
    0 &\quad \text{for $E'$ in $\calA_X \setminus \calA_1$.}
  \end{cases}
%  \label{def-r-X1}
\end{equation*}
Then for $E_0 < E < E_1$, for $q$ as in Eq.~(\ref{def-q}) and for
$E'$ in the set~$\calA_X$, the linear-linear form of unscaled direct interpolation
with extrapolation becomes as in Eq.~(\ref{def-pi-X}),
\begin{equation}
  r_X(E', E ) = ( 1 - q )\, r_X(E', E_0 ) + q\, r_X(E', E_1 ).
  \label{r-direct-extrapolation}
\end{equation}
The extrapolation version of direct interpolation of the Kallbach-Mann
$r$ parameter as in Eq.~(\ref{r-direct-extrapolation}) is implemented in
the \gettransfer\ code.

For unscaled direct interpolation of the Kalbach-Mann $r$ parameter with
truncation, the outgoing energy $E'$ is restricted to the common
domain $\calA_T = \calA_0 \cap \calA_1$, and there is no change
of scale analogous to that used for probability densities in
Eq.~(\ref{def-pi-T01}).  Thus, the truncated Kalbach-Mann $r$ parameters
for incident energies $E_0$ and~$E_1$ are
\begin{equation*}
  r_T(E', E_0 ) = \begin{cases}
    r(E', E_0 ) &\quad \text{for $E'$ in $\calA_T$,} \\
    0 &\quad \text{for $E'$ in $\calA_0 \setminus \calA_T$,}
  \end{cases}
%  \label{def-r-T0}
\end{equation*}
and
\begin{equation*}
  r_X(E', E_1 ) = \begin{cases}
    r(E', E_1 ) &\quad \text{for $E'$ in $\calA_T$,} \\
    0 &\quad \text{for $E'$ in $\calA_1 \setminus \calA_T$.}
  \end{cases}
%  \label{def-r-T1}
\end{equation*}
The linear-linear version of unscaled direct
interpolation with truncation is
\begin{equation}
  r_T(E', E ) = ( 1 - q )\, r_T(E', E_0 ) + q\, r_T(E', E_1 )
  \label{r-direct-truncation}
\end{equation}
with $E'$ restricted to~$\calA_T$.
The \gettransfer\ code does not currently implement unscaled direct
interpolation with truncation of the Kalbach-Mann $r$ parameter
given in Eq.~(\ref{r-direct-truncation}).

There is also an unscaled version of unit-base interpolation with
Eqs.~(\ref{unitbaseMap}) and~(\ref{unitbaseMap1}) replaced by
\begin{equation*}
 \begin{split}
  \widehat r(\Ehat', E_0) &= r(E', E_0), \\
  \widehat r(\Ehat', E_1) &= r(E', E_1), \\
 \end{split}
\end{equation*}
for $0 \le \Ehat' \le 1$ with $\Ehat'$ as in Eq.~(\ref{unit-base-map-cum})
for $E = E_0$ and as in Eq.~(\ref{unit-base-map1})
for $E = E_1$.  For linear-linear unscaled unit-base interpolation
to incident energy $E$ with $E_0 < E < E_1$, interpolate the
minimal and maximal outgoing energies as in Eq.~(\ref{EoutRange}),
interpolate $\widehat r$ using
$$
    \widehat r(E', E ) = ( 1 - q )\, \widehat r(E', E_0 ) + q\, \widehat r(E', E_1 ),
$$
and invert the unit-base map using Eq.~(\ref{range-inv})
and
$$
  r(E', E) = \widehat r(\Ehat', E)
$$
for $\Emin' \le E' \le \Emax'$.

When the energy probability density $\pi_E( E' \mid E )$ in Eq.~(\ref{Kalbach-prob})
is interpolated using the method of cumulative points, the interpolated values of
$r(E', E)$ in Eq.~(\ref{Kalbach-eta}) are obtained using the method of
unscaled cumulative points defined as follows.  Because the data for
 $r( E' , E )$ and  $\pi_E( E' \mid E )$ are given at the same energy points
 $E$ and~$E'$, it is natural to use for $r( E' , E_0 )$ and $r( E' , E_1 )$ the
 intervals  $\calB_{ \ell}(E_k )$, k = 0,~1, constructed for $\pi_E( E' \mid E_k )$
in Eq.~(\ref{def-B-ell}).  The \gettransfer\ code uses unscaled unit-base interpolation
between $r( E', E_0)$ on $\calB_{\ell}(E_0 )$ and  $r( E', E_0)$ on $\calB_{ \ell}(E_1 )$
in sequence for $\ell = 1,$ 2, $\ldots\,$, $L$. This method is applicable
even when a set $\calB_{ \ell}(E_k )$ reduces to a point as discussed in
Section~\ref{Sec:cum-points-trivial}, as here is no problem of possible division by zero.


\documentclass{amsart}
\usepackage{style/preamble}
\usepackage{parskip}
\begin{document}
  \section{Complex analysis theorems}
  Let $U$ be an open subset of $\bbc$.
  Let $f: U \rightarrow \bbc$ be a continuous function.

  $f$ is called (once) \emph{complex differentiable} at $a \in U$ if the limit
  \begin{align*}
    f'(z) := \lim_{h \rightarrow 0} \dfrac{f(z + h) - f(z)}{h}
  \end{align*}
  exists for all $z$ in some neighborhood of $a$.

  \begin{theorem}[Taylor series]
    If $f$ is once differentiable at $a$, then $f$ is infinitely differentiable at $a$ and $f$ has a Taylor series converging to it in a neighborhood of $a$.
    \begin{align*}
      f(z) = f(a) + f'(a){(z-a)} +  f''(a)\dfrac{(z-a)^2}{2!} + \dots +  f^{(n)}(a)\dfrac{(z-a)^n}{n!} + \dots
    \end{align*}
  \end{theorem}

  \begin{theorem}[Open mapping theorem]
    If $f$ is complex differentiable then for any open set $V \subseteq U$, the set $f(V)$ is an open subset of $\bbc$.
  \end{theorem}

  \begin{theorem}[Isolated zeroes]
    If $f$ is complex differentiable then the set of zeroes of $f$ are isolated i.e. if $f(a) = 0$ for some $a \in U$ then there exists a neighborhood $V$ of $a$ such that $a$ is the only zero of $f$ in $V$.
  \end{theorem}

\vspace{1cm}

  A complex differentiable function $g: \bbc \rightarrow \bbc$ is called an \emph{entire} function.
  \begin{theorem}[Liouville's theorem]
    Let $g$ be an entire function.
    If there exists a real number $M$ such that $|g(z)| < M$ for all $z \in \bbc$ then $g(z)$ is a constant function.
  \end{theorem}

  \begin{theorem}[Little Picard's theorem]
    Let $g$ be an entire function.
    If $g$ is not a constant function then the image of $g$ is either the whole complex plane or the plane minus a single point.
  \end{theorem}
\end{document}