% -*- 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}{06}{
%Prerequisites:

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

\problem{Problem 1 (5 points)}
%---------------------------------------------------------------

Estimate the Euler's number $e \approx 2.71\ldots$ via evaluation of
the following integral with the Monte-Carlo method
\begin{eqnarray*}
	e=\int_0^1 (e^x+1) dx
\end{eqnarray*}




\problem{Problem 2 (5 points)}
%---------------------------------------------------------------

For the  problem above. Plot  (in loglog  space) the absolute deviation  of
the integral from  its true  value  as a  function  of the  random  points number  ($N$)
spanning logarithmically from  10 to $10^6$. For  each $N$ do  it at least 100  times, mark
such  points as  small dots  (use matlab \mat{'.'}  marker specifier)  on your  plot,
calculate and show on the same plot the mean of  the integral value error
estimation at a particular $N$ with a circle marker (use matlab \mat{'o'} marker specifier).

Does the $e$ estimate error drop as $1/\sqrt{N}$? Show this dependence on the
same plot.

\problem{Problem 3 (5 points)}
%---------------------------------------------------------------
Consider the LCG random generator with $a=11$, $c=2$, $m=65535$, and
$r_1=1$. What is the best case scenario for the length/period of the random
sequence of a LC generator with $m=65535$? Estimate the actual length of the
non repeating sequence.

\problem{Problem 4 (5 points)}
%---------------------------------------------------------------
Modify the colony life script example to take in account helping neighbors.
Leave the probability to heal  a cell without alive neighbors as it is,
double the healing probability for a cell with one alive neighbor, and triple it
if a cell has alive neighbors on both sides. We assume that illness does not prevent a
helping/healing action, i.e. a neighbor must be alive to help
but it might have an illness too.

{\bf Make sure that you are using matlab random generator,  i.e., \mat{rand}}.

Is the saying ``the best neighbor is the dead neighbor'' still true?



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