Homework 10

  • Type your name and email in the “Student details” section below.

  • Develop the code and generate the figures you need to solve the problems using this notebook.

  • For the answers that require a mathematical proof or derivation you can either:

    • Type the answer using the built-in latex capabilities. In this case, simply export the notebook as a pdf and upload it on gradescope; or

    • You can print the notebook (after you are done with all the code), write your answers by hand, scan, turn your response to a single pdf, and upload on gradescope.

  • The total homework points are 100. Please note that the problems are not weighed equally.


  • This is due before the beginning of the next lecture.

  • Please match all the pages corresponding to each of the questions when you submit on gradescope.

Student details

  • First Name:

  • Last Name:

  • Email:

import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set(rc={"figure.dpi":100, 'savefig.dpi':300})
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina', 'svg')
import numpy as np
import scipy.stats as st

Problem 1 - An alternative way to construct the generalized uniform distribution \(U([a,b])\)

Let \(Z\) be a standard uniform random variable:

\[ Z\sim U([0,1]). \]

Define the random variable:

\[ X = a + (b-a) Z. \]
  • Show that:

\[ X\sim U([a,b]). \]

Hint: Prove that the CDF of \(X\) is \(F_X(x) = p(X\le x) = \frac{x-a}{b-a}\). This is one line.


  • The function numpy.random.rand gives you uniform random samples in \([0, 1]\). Take 1,000 such samples and transform them to uniform samples in \([-1, 5]\). Hint: Fill in the missing code below.

a = -1
b = 5
z = np.random.rand(1000)
x = # Your code here

Test if you are getting the right answer by doing the histogram of your samples (it should be almost flat between -1 and 5):

fig, ax = plt.subplots()
ax.hist(x, density=True, alpha=0.5)

Problem 2 - The Exponential distribution

The Exponential distribution models the probability distribution of the time between events which occur continuously and independently at a constant rate. Examples of such a situation are:

  • The time between phone calls in a help center.

  • The time between the arrival of cars at a toll station.

  • The time between the arrival of customers.

  • The time between two earthquakes.

  • The time between two micrometeoroid impacts on an Moon research base.

  • The time between faults in a mechanical system. However, this is a gross approximation because the rate of faults in a mechanical system increases with time, it is not constant.

We write:

\[ T \sim \text{Exp}(\lambda), \]

and we read:

\(T\) follows an Exponential distribution with rate parameter \(\lambda\).

The rate parameter \(\lambda\) is positive and has units of inverse time. You can think of \(\lambda\) as the number of events per unit of time.

The CDF of the Exponential is:

\[\begin{split} F(t) = \begin{cases} 0,& t < 0,\\ 1 - e^{-\lambda t},& t \ge 0. \end{cases} \end{split}\]
  • Prove mathematically that the PDF of the random variable \(T\) is:

\[ p(t) = \lambda e^{-\lambda t}. \]

Hint: Use one of the properties of the PDF.


  • Micrometeoroids make space exploration very challenging. Even though the mass of these projectiles is very small (less than 1 gram), they move with a very high-velocity (of the order of 10 km per second) and thus they are will be gradually degrading the protective layers of deep space habitats. For a Moon base with an area of 1000 squared meters, the rate of micrometeoroid impacts is about:

\[ \lambda = 3\times 10^{-6}\;\text{s}^{-1}. \]

Read the scipy.stats.expon documentation and make an Exponential random variable \(T\) with this rate:

# You cannot use lambda because it is a reserved word.
# Call the rate lam instead:
lam = 3e-6 # in inverse seconds
T = st.expon(scale= # PICK THE RIGHT VALUE HERE
  • Take 1000 samples from the random variable you just constructed and draw their histogram.

# Your code here
  • Plot the CDF of \(T\):

# Your code here
  • Find the probability that we have a micrometeoroid impact within a day. Hint: Remember that the units of \(T\) are seconds.

# Your code here
  • Plot the PDF of T.

# Your code here