\documentclass[twocolumn]{article}
% \documentclass{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf 1.} Suppose $f_X(t) = 1/(2t^2)$ for $1 < t < 2$, with the value 0
elsewhere.  

\begin{itemize}

\item [(a)] (15) Find $P(X > 1.5)$.

\item [(b)] (15) Find $EX$.

\end{itemize}

{\bf 2.} Consider the analysis of the ALOHA network, Section 4.5.  (Keep
in mind that that state numbers start at 0 but the row/column numbers in
the R code start at 1.)

\begin{itemize}

\item [(a)] (20) In the R code on p.101, give a line (say, to be placed at
the end) that will print out $P(X_{200} = 1 | X_{198} = 2)$.

\item [(b)] (20) Suppose there are three nodes in the network, rather than
two, and that $p$ and $q$ are 0.4 and 0.3, respectively.  Our states are
now 0, 1, 2 and 3.  Find $p_{32}$

\end{itemize}

{\bf 3.}  Consider bus ridership example, Section 4.6.  

\begin{itemize}

\item [(a)] (15) Now that we have imposed a bus capacity of 20, we need to
modify the simulation on p.20.  State a line to add to the code to
reflect this.  Place the line position in a comment, e.g.  

\begin{lstlisting}
count <- count/2  # insert after line 6 
\end{lstlisting}

Do NOT change existing lines.

\item [(b)] (15) Find $p_{19,20}$.

\end{itemize}


\onecolumn

\newpage

{\bf Solutions:}

{\bf 1a.} 

\begin{lstlisting}
integrate(function(t) 1/(2*t^2),1.5,2)
\end{lstlisting}

{\bf 1b.} 

\begin{lstlisting}
integrate(function(t) 1/(2*t),1,2)
\end{lstlisting}

{\bf 2a.} 

\begin{lstlisting}
(transmat %*% transmat)[3,2]
\end{lstlisting}

{\bf 2b.} The quantity $p_{32}$ is the probability that exactly 1 node
tries to send, so the answer is

\begin{lstlisting}
dbinom(1,3,0.4)
\end{lstlisting}

{\bf 3a.}

\begin{lstlisting}
passengers <- min(passengers,20)  # insert after line 12
\end{lstlisting}

{\bf 3b.}  The possibilities are

\begin{itemize}

\item at least 1 person tries to board and no one alights

\item 2 people try to board and 1 alights

\end{itemize}

So the desired probability is

\begin{lstlisting}
(0.4 + 0.1) * dbinom(0,19,0.2) + 0.1 * dbinom(1,19,0.2) 
\end{lstlisting}

\end{document}
