Homework 5 Key

CHE 116: Numerical Methods and Statistics

(2/13/2020)


1. Probability Distribution Identification

State What probability distribution best describes the following random numbers:

  1. The number of times you win in five boxing matches
  2. Number of days until you drop and break your phone.
  3. If the temperature is above or below freezing
  4. The value of the temperature outside
  5. The number of students who get 4.0 when graduating
  6. The number of minutes between emails
  7. The number of emails received in one minute

2. Computing Outcome Probabilities

For the following problems, choose and state an appropriate distribution, write out its parameters based on the problem statement and then compute the requested quantity. Write the distribution information in Markdown/LaTeX and compute answers in Python. Choose only from the distributions presented in lecture.

  1. The probability of success for becoming a successful actor is 0.01. What is the probability of not becoming a successful actor?

  2. Five people are competing in an ultra marathon. The probability to complete the ultra marathon is 50%. What is the probability that 3 complete the ultra marathon?

  3. You are watching deer walk across a street. 10 deer take 5 minutes to cross the street.

3 Plotting Probability Distributions

For each problem below, use numpy to create x and y arrays which are plotted. Be sure to label your x-axis, y-axis, put the problem number as the title, use at least 500 points, make your figures be 4x3 inches, and add a legend if you have more than one line being plotted.

  1. [6 points] Plot $y = x^2$ from $-1$ to $1$

  2. [8 points] A hanging rope, wire, or chain follows a catenary curve ($y = a\textrm{cosh}\frac{x}{a} - a$), although many including Galileo mistakenly believed hanging ropes a parabolas. Compare the catenary and parabolic ($y = x^2$) curves over $-1$ to $1$ where $a = 0.63$.

  3. [8 points] Compare the functions $\cos x$ and $\cosh x - 1$ from $-\pi/2$ to $\pi/2$

4 Working with Probability Distributions

Use this probability distribution:

$$ Q = \{\textrm{red},\textrm{ green}, \textrm{blue}\} $$$$ P(\textrm{red}) = 0.1,\, P(\textrm{green}) = 0.5,\, P(\textrm{blue}),\, = 0.4 $$
  1. [2 points] Create a dictionary called prob where the key is the colors as a string and the values are the probability.

  2. [4 points] Starting with this fragment, show that your probability distribution is normalized.

for key,value in prob.items():
    print(key, value)
  1. [4 points] Let's define a random variable $X$ that is 1 for red, 2 for green, and 0 for blue. Using your for loop from 4.2, use boolean statements to set a variable $x$ to what the value of $X$ should be using the key variable. Print out key, x, which should look like red, 1, green, 2...

  2. [4 points] Compute the expected value of x using the for loop from 4.3

  3. [4 points] Compute the variance by hand, showing the steps in Markdown


In [15]:
#4.1
prob = {'red': 0.1, 'green': 0.5, 'blue': 0.4}

In [16]:
#4.2
psum = 0
for key, value in prob.items():
    psum += value
print(psum)


1.0

In [17]:
#4.3
for key,value in prob.items():
    x = 0
    if key == 'red':
        x = 1
    elif key == 'green':
        x = 2
    print(key, x)


red 1
green 2
blue 0

In [18]:
#4.4
ev = 0
for key,value in prob.items():
    x = 0
    if key == 'red':
        x = 1
    elif key == 'green':
        x = 2
    ev += x * value
print(ev)


1.1

4.5

$$ Var(x) = E[x^2] - E[x]^2 $$$$ E[x] = \sum_Q X(q)P(q) $$$$ E[x] = 1 \times 0.1 + 2 \times 0.5 + 0 \times 0.4 = 1.1 $$$$ E[x] = 1^2 \times 0.1 + 2^2 \times 0.5 + 0^2 \times 0.4 = 2.1 $$$$ Var(x) = 2.1 - 1.1^2 = 0.89 $$