%10.11.13
\documentclass[a4paper, 12pt]{article}
%\usepackage[magyar]{babel}
\usepackage{t1enc}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage[leqno,intlimits]{amsmath}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{epsfig}
%\usepackage{subfigure}
\usepackage{psfrag}
\usepackage{enumerate}
\usepackage{mdwlist}
% \usepackage{enumitem}
\usepackage{color}
%\usepackage{enumitem}


%\hyphenpenalty=10
\tolerance=1000

\setlength{\marginparwidth}{0pt}
\addtolength{\textwidth}{100pt}
\addtolength{\hoffset}{-50pt}
\addtolength{\textheight}{160pt}
\setlength{\voffset}{-80pt}

\newcommand*{\hop}{\bigskip\noindent}
\newcommand{\TT}{\mathbb{T}}
\newcommand{\Sb}{\mathbb{S}}
\newcommand{\Rb}{\mathbb{R}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\EE}{\mathbb{E}}
\newcommand{\cF}{\mathcal{F}}
\newcommand{\prob}{\mathbb{P}}
\newcommand{\expect}{\mathbb{E}}
\newcommand{\var}{\textbf{Var}}

\begin{document}
\begin{center}
{\bf Advanced Mathematics for Electrical Engineers B\\
homeworks for the ``Stochastics 2'' part}\\
fall semester 2014
\end{center}
\noindent
Every week, the assigned homeworks are worth 1 point in total.

\begin{itemize}
%
 \item[{\bf HW 1:}] (due date: 15.09.2014 -- \textbf{extended to 24.09.2014})
 \begin{itemize}
   \item[HW 1.1] A server computer has $70$ users. At any given time, some users are ``logged in'' to the server, while others are not.
   On a Monday morning each user wants to log in with probability $\frac{3}{10}$, independently of the other users.
    \begin{enumerate}[a.)]
     \item What is the probability that there will be exactly $21$ users logged in?
     \item If more that $65$ users want to log in, the server becomes overloaded, and will not work correctly. What is the probability that this happens?
    \end{enumerate}
   \noindent\textbf{Solution:} Let $X$ denote the number of users logged in (on that Monday morning). You can view each user as ``trying'' to log in, and having success with probability $p=\frac{3}{10}$, independently of the others. So $X$ is the number of successes out of $n=70$ independent experiments, each having success probability $p$. So $X$ has \emph{binomial} distribution with parameters $n=70$ and $p=\frac{3}{10}$. Notation: $X\sim Bin(70;\frac{3}{10})$. This means that, with the notation $q:=1-p$,
   $$\prob(X=k)=\binom{n}{k} p^k q^{n-k}\quad\text{for $k=0,1,\dots,n$}.$$
   In our case ($n=70$, $p=\frac{3}{10}$)
   $$\prob(X=k)=\binom{70}{k} \left(\frac{3}{10}\right)^k \left(\frac{7}{10}\right)^{70-k}\quad\text{for $k=0,1,\dots,70$}.$$
   So
   \begin{enumerate}[a.)]
    \item with $k=21$ we get $\prob(X=21)=\binom{70}{21} \left(\frac{3}{10}\right)^{21} \left(\frac{7}{10}\right)^{49}$.
    \item $$\prob(X>65)=\sum_{k=66}^{70} \prob(X=k) = \sum_{k=66}^{70} \binom{70}{k} \left(\frac{3}{10}\right)^k \left(\frac{7}{10}\right)^{70-k}.$$
   \end{enumerate}
   %
   \item[HW 1.2] Let the random variable $X$ be binomially distributed with parameters $n$ and $p$. Use a calculator or a computer to calculate the value $\prob(X=3)$ \emph{numerically}, with $4$ digits precision, for the following parameter values:
    \begin{enumerate}[a.)]
     \item $n=10$, $p=\frac{2}{10}$
     \item $n=100$, $p=\frac{2}{100}$
     \item $n=1000$, $p=\frac{2}{1000}$
     \item $n=10000$, $p=\frac{2}{10000}$
     \item Calculate the value of $e^{-2}\cdot\frac{2^3}{3!}$, where $e$ is the Euler number $e\approx 2.71828182845905$.
    \end{enumerate}
    \noindent\textbf{Solution:} We are calculating
    $$\prob(X=3)=\binom{n}{3} p^3 q^{n-3}=\frac{n(n-1)(n-2)}{3\cdot 2\cdot 1}p^3 (1-p)^{n-3}$$
    \emph{numerically, with four digits precision!}
    \begin{enumerate}[a.)]
     \item For $n=10$, $p=\frac{2}{10}$ we get $\frac{10\cdot 9\cdot 8}{3\cdot 2\cdot 1}\left(\frac{2}{10}\right)^3 \left(\frac{8}{10}\right)^{7}=0.2013$
     \item For $n=100$, $p=\frac{2}{100}$ we get $\frac{100\cdot 99\cdot 98}{3\cdot 2\cdot 1}\left(\frac{2}{100}\right)^3 \left(\frac{98}{100}\right)^{97}=0.1823$
     \item For $n=1000$, $p=\frac{2}{1000}$ we get $\frac{1000\cdot 999\cdot 998}{3\cdot 2\cdot 1}\left(\frac{2}{1000}\right)^3 \left(\frac{998}{1000}\right)^{997}=0.1806$
     \item For $n=10000$, $p=\frac{2}{10000}$ we get $\frac{10000\cdot 9999\cdot 9998}{3\cdot 2\cdot 1}\left(\frac{2}{10000}\right)^3 \left(\frac{9998}{10000}\right)^{9997}=0.1805$
     \item With four digits precision, $e^{-2}\cdot\frac{2^3}{3!}=0.1804$. This illustrates the convergence of binomial probabilities to the Poisson probability -- more precisely, the convergence of binomial distributions with $n\cdot p=2$, as $n\to\infty$, to the Poisson distribution with parameter $\lambda=2$.
    \end{enumerate}
 \end{itemize}
%
 \item[{\bf HW 2:}] (due date: 01.10.2014)
 \begin{itemize}
   \item[HW 2.1] We toss a fair coin. If the result is heads, we toss it another $2$ times (and then stop). If it is tails, then we toss it another $3$ times (and then stop). Let $X$ denote the total number of heads we see (during all the $3$ or $4$ tosses). Use the law of total expectation to calculate the expectation of $X$.
   
   \noindent\textbf{Solution:} Introduce the events $A_1$: the 1st toss is Heads; $A_2$: the 1st toss is Tails. These clearly form a partition (meaning that surely exactly one of them occurs), and $\prob(A_1)=\prob(A_2)=\frac12$.
   
   Now observe that for any $k$, the expected number of ``Heads'' in $k$ tosses is $k\cdot \frac12$. Moreover, if $A_1$ occurs, then the first toss contributes to $X$, while if $A_2$ occurs, then it does not. This means that
   $$\expect(X|A_1)=1+\expect(\text{heads in $2$ tosses})=1+2\cdot \frac12 = 2,$$
   $$\expect(X|A_2)=0+\expect(\text{heads in $3$ tosses})=0+3\cdot \frac12 = \frac32.$$
   Now the law of total expectation gives
   $$\expect X = \prob(A_1)\expect(X|A_1)+\prob(A_1)\expect(X|A_1)=\frac12\cdot 2+\frac12\cdot \frac32 = \frac74.$$
   %
   \item[HW 2.2] Let the random variable $Y$ have binomial distribution with parameters $n=10$ and $p=\frac13$. 
   \begin{enumerate}[a.)]
     \item Calculate the generating function of $Y$. \emph{(Hint: to calcualte the sum in a closed form, use the binomial theorem: $(a+b)^n=\sum_{k=0}^n \binom{n}{k}a^k b^{n-k}$.)}
     \item Use the properties of the generating function to calcualte the expectation and the variance of $Y$.
    \end{enumerate}
   \noindent\textbf{Solution:}
   \begin{enumerate}[a.)]
    \item $Y$ being binomial means $\prob(Y=k)=\binom{n}{k}p^k q^{n-k}$ for $k=0,1,\dots,n$ and $0$ otherwise. (Here $q$ is just a notation for $1-p$.) So the generating function is
    $$g(z)=\sum_{k=0}^\infty\prob(Y=k) z^k = \sum_{k=0}^n \binom{n}{k}p^k q^{n-k} z^k = \sum_{k=0}^n \binom{n}{k}(pz)^k q^{n-k} = (pz+q)^n.$$
    In the last step we used the Binomial Theorem. In our special case $n=10$, $p=\frac13$ and $q=\frac23$,
    $$g(z)=\left(\frac13 z+\frac23\right)^{10}.$$
    \item Differentiating twice, we get
    $$g'(z)=n(pz+q)^{n-1}p,$$
    $$g''(z)=n(n-1)(pz+q)^{n-2}p^2.$$
    Substituting $z=1$ and using $p+q=1$ gives
    $$g'(1)=n(p+q)^{n-1}p=np,$$
    $$g''(1)=n(n-1)(p+q)^{n-2} p^2=n^2p^2-np^2.$$
    So, using the properties of the generating function:
    $$\expect Y = g'(1)=np,$$
    $$\var Y = g''(1)+g'(1)+(g'(1))^2=n^2p^2-np^2+np-n^2p^2=np(1-p)=npq.$$
    In our special case $n=10$, $p=\frac13$ and $q=\frac23$,
    $$\expect Y = 10\cdot \frac13 =\frac{10}{3},$$
    $$\var Y = 10\cdot \frac13\cdot\frac23=\frac{20}{9}.$$
   \end{enumerate}

 \end{itemize}
%

%
\end{itemize}
%

\end{document}

