% -*- latex -*-
\documentclass[letter,12pt]{article}
%---------------------------------------------------------------
%\usepackage{listings}
\usepackage[framed]{matlab-prettifier}
\usepackage{color}
\usepackage{fullpage}
\usepackage{enumitem} % control over itemize, list environment
%---------------------------------------------------------------


\begin{document}
\newcommand{\hwtitle}[1]{%
	\begin{center}
		\Large  \bf Homework #1%
	\end{center}%
}

\newcommand{\mat}[1]{% matlab code
%{\color{blue}\texttt{#1}}%
	% this one does not work inside of captions
	{\lstinline[style = Matlab-editor, basicstyle = \mlttfamily, columns=fixed]!#1!}%
	% this one work but style is different
	%{\lstinline[columns=fixed]!#1!}%
}
%---------------------------------------------------------------
\newcommand{\problem}[1]{% homework problem
	%{\item  \bf #1%}
\item {\bf #1{}:}% the next blank line is important

}

\newenvironment{homework}[2]%
{%
	\hwtitle{#1}
	#2% Prerequisites

	\begin{enumerate}[
		label={\bf Problem\ \arabic*}, 
		leftmargin=0pt,
		start,
		labelindent=0pt,
		widest=20, align=left, itemindent=!
		]
}%
{%
	\end{enumerate}
}%

%---------------------------------------------------------------
\begin{homework}{07}{
%Prerequisites:

General comments: 
\begin{itemize}
	\item Do not forget to run some test cases. 
\end{itemize}
}

\problem{(2 points)}
%---------------------------------------------------------------
Prove (analytically) that the golden section algorithm $R$ is still given by the same
expression even if we need to choose $a'=x_1$ and
$b'=b$.

\problem{(3 points)}
%---------------------------------------------------------------
Assume that the initial spacing  between  initial bracket points is $h$.
Estimate (analytically) how many iterations it requires to narrow the bracket to
the $10^{-9}\times h$ space.


\problem{(5 points)}
%---------------------------------------------------------------
Implement the golden section algorithm.
Do not forget to check your code with simple
test cases.
Find where the function
$E1(x)=x^2-100*(1-\exp(-x))$ has a minimum. 


\problem{(5 points)}
%---------------------------------------------------------------
For the coin flipping game described on lecture 14, find the optimal
(maximizing your gain)
betting fraction using the golden section algorithm and Monte Carlo
simulation. Feel free to reuse provided complimentary codes. 

Note: you need a lot of game runs to have reasonably
small uncertainty for the merit function evaluations. I would suggest
to average at least  1000 runs with the length of 100 coin flips  each.

\problem{(5 points)}
%---------------------------------------------------------------
Find the point where the function 
\begin{eqnarray*}
F(x,y,z,w,u)=(x-3)^2 + (y-1)^4 + (u-z)^2 + (u-2*w)^2 + (u-6)^2 + 12
\end{eqnarray*}
has a minimum. What is the value of
$F(x,y,z,w,u)$ at this point?

\end{homework}
%---------------------------------------------------------------
\end{document}
%---------------------------------------------------------------
