\documentclass[a4paper]{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{enumitem}

\graphicspath{ {./images/} }

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Question \arabic{#1} (continued)}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Question \arabic{#1} (continued)}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Question \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Question \arabic{homeworkProblemCounter}}{}\nobreak{}

\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Question \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

\newcommand{\hmwkClass}{INF 1004 Mathematics 2}
\newcommand{\hmwkTitle}{Tutorial\ \#6}
\newcommand{\hmwkAuthorName}{\textbf{Woon Jun Wei}}
\newcommand{\hmwkStudentID}{\textbf{2200624}}

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass \\ \hmwkTitle}}\\
    \vspace{3in}
}

\author{\hmwkAuthorName \\ \hmwkStudentID}
\date{\today}

\renewcommand{\part}[1]{\textbf{\large Part \arabic{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large My Solution\\}}
\newcommand{\answer}{\textbf{\large Sample Solutions\\}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle
\pagebreak

\begin{homeworkProblem}
A sample of people have been assigned to fly to Mars. The frequencies of those in each
age-group are given in the table below. Frequency represents the total number of
people in each age range. Note, all ages are only measured (discretely) in years, and
each range is inclusive of its boundaries.
\begin{enumerate}[label=\alph*)]
    \item What is the Mode range for these data?
    \item What is the interpolated Median (Q) for these data?
    \item Calculate the Mean for these data.
    \end{enumerate}

\begin{center}
    \begin{tabular}{|c|c|}
        \hline
        Age Range & Frequency \\
        \hline
        1 to 8 & 2\\
        \hline
        9 to 20 & 14\\
        \hline
        21 to 40 & 16\\
        \hline
        41 to 60 & 93\\
        \hline
        61 to 80 & 140\\
        \hline
        81 to 105 & 35\\
        \hline
    \end{tabular}
\end{center}

\solution

\begin{center}
    \begin{tabular}{|c|c|c|c|}
        \hline
        Age Range & Frequency & Midpoint & $cf$\\
        \hline
        1 to 8 & 2 & 4.5 & 2\\
        \hline
        9 to 20 & 14 & 14.5 & 16\\
        \hline
        21 to 40 & 16 & 30.5 & 32\\
        \hline
        41 to 60 & 93 & 50.5 & 125\\
        \hline
        61 to 80 & 140 & 70.5 & 265\\
        \hline
        81 to 105 & 35 & 93 & 300\\
        \hline
    \end{tabular}
\end{center}

\part

Modal Range: 61 to 80\\

\part

$$
\begin{align}
Q &= L_m +\Bigr( \frac{\frac{n}{2} -cf_{m-1}}{f_m}\Bigr)w_m\\
  &= 61 + \Bigr( \frac{\frac{300}{2} - 125}{140}\Bigr) (80-61)\\
  &= 64.39285714\\
  &\approx \boxed{64.39}
\end{align}
$$

\part

$$
\begin{align}
    \bar{x} &= \frac{\sum x f_i}{n}\\
            &= \frac{(4.5)(2) + (14.5)(14) + (30.5)(16) + (50.5)(93) + (70.5)(140) + (93)(35)}{300}\\
            &= \frac{19931.5}{300}\\
            &= 66.43833333\\
            &\approx \boxed{66.44}
\end{align}
$$

\end{homeworkProblem}

\pagebreak
\begin{homeworkProblem}
You are taking random samples of seashells on a beach. The seashells are either
univalves or bivalves. You know that 76\% of seashells on the beach are univalves. You
pick 100 random samples of seashells from the beach. Taking each seashell is
independent from the others and the probability of selecting a univalve or a bivalve
remains the same for each sample.\\

\begin{enumerate}[label=\alph*)]
    \item Given that you hope to pick as many bivalves as possible, answer the following.
    \item What are the mean (expected value) and variance for taking 100 random samples of seashells from the beach?
    \item What is the probability that you select exactly one bivalve seashell in your 100 samples?
    \item What is the probability of collecting more than \underline{86\%} univalve seashells in the 100 samples?
\end{enumerate}

\solution

$$X \sim B(100, 0.24)$$

\part

$$
\begin{align}
    E(x) &= np\\
         &= 100 \cdot 0.24\\
         &= \boxed{24}\\\\
    Var(x) &= np(1-p)\\
           &= 100 \cdot 0.24 \cdot 0.76\\
           &= \boxed{18.24}
\end{align}
$$

\part

$$
\begin{align}
    P(X = 1) &= \binom{100}{1}(0.24)^1(0.76)^{100-1}\\
             &= 3.8085 \times 10^{-11}\\
             &\approx \boxed{3.81 \times 10^{-11}}
\end{align}
$$

\part

$$ X \sim B(100, 0.76)$$

$$
\begin{align}
    P(X > 86) &= P(Y > 86.5)\\
              &= P(Z > \frac{86.5 - (100\cdot 0.76)}{\sqrt{18.24}})\\
              &= P(Z  > 2.4585)\\
              &= P(Z > 2.46)\\
              &= 1- P(Z \leq 2.46)\\
              &= 1-0.9931\\
              &= \boxed{0.0069}
\end{align}
$$


\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    You have landed on an alien planet. When you go out to explore the planet you are
guaranteed to encounter one alien. There are three types of aliens: Circles, Squares, and
Triangles. You know that the chance of encountering a Circle is 50\%, Square is 30\% and
Triangle is 20\%.\\

Unfortunately, the aliens are sometimes unfriendly and may attack. This likelihood of
being attacked depends on the type of alien you encounter. If you encounter (given) a
Circle it has a 10\% chance of attacking you, encountering (given) a Square has a 30\%
chance of attacking you, while encountering (given) a Triangle has an 80\% chance of
attacking you.\\

Given this information, answer the following questions.

\begin{enumerate}[label=\alph*)]
    \item When you explore the planet, what is the probability of you being attacked by an alien?
    \item When you explored the planet: (given) if you were NOT attacked by an alien, what is the probability that you encountered a Circle?
    \item When you explored the planet: (given) if you were attacked by an alien, what is the probability that you encountered a Triangle?
\end{enumerate}

\solution

\part

$$
\begin{align}
    P(a) &= (0.5)(0.1) + (0.3)(0.3) + (0.2)(0.8)\\
         &= \boxed{0.3}
\end{align}
$$

\part

$$
\begin{align}
    P(c|a^c) &= \frac{P(c\cap a^c)}{P(a^c)}\\
             &= \frac{(0.5)(0.9)}{(0.5)(0.9) + (0.3)(0.7) + (0.2)(0.2)}\\
             &= 0.6428571429\\
             &\approx \boxed{0.64}
\end{align}
$$

\part

$$
\begin{align}
    P(T|a) &= \frac{P(T\cap a)}{P(a)}\\
           &= \frac{0.2 \cdot 0.8}{0.3}\\
           &= 0.5333333333\\
           &\approx \boxed{0.53}
\end{align}
$$



\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
Flying from earth to a distant planet may take a variety of different times, depending on
random factors of space flight. The times are normally distributed with a mean time of 40
weeks and standard deviation of 5 weeks.\\

Given this information, answer the following.

\begin{enumerate}[label=\alph*)]
    \item What is the probability that flying from earth to the planet takes more than 35 weeks?
    \item What is the probability that flying from earth to the planet takes less than 30 weeks?
    \item What is the probability that flying from earth to the planet takes between 25 and 45 weeks?
\end{enumerate}

\solution

$$X \sim N(40, 5^2)$$

\part

$$
\begin{align}
    P(X > 35) &= P(Z > \frac{35 - 40}{5})\\
              &= P(Z > -1)\\
              &= P(Z \leq 1)\\
              &= \boxed{0.8413}
\end{align}
$$

\part

$$
\begin{align}
    P(X < 30) &= P(Z < \frac{30 - 40}{5})\\
              &= P(Z < -2)\\
              &= P(Z \geq -2)\\
              &= 1 - P(Z < -2)\\
              &= 1 - 0.9772\\
              &= \boxed{0.0228}
\end{align}
$$

\part

$$
\begin{align}
    P(25 < X < 45) &= P(25 < Z < 45)\\
                   &= P(\frac{25 - 40}{5} < Z < \frac{45 - 40}{5})\\
                   &= P(-3 < Z < 1)\\
                   &= P(Z \leq 1) - P(Z \leq -3)\\
                   &= P(Z \leq 1) - (1- P(Z \leq 3))\\
                   &= 0.8413 - (1 - 0.9987)\\
                   &= \boxed{0.84}
\end{align}
$$

\end{homeworkProblem}

\end{document}
