Homework 3

CHE 116: Numerical Methods and Statistics

Prof. Andrew White

Version 1.6 (2/3/2015)


1. Identifying Distributions (5 Points)

List if a distribution is continuous or discrete, its support, and an example of a random variable which follows the distribution. 1 Bonus point per problem for identifying a rv related to chemical engineering.

  1. Geometric distribution
  2. Poisson Distribution
  3. Binomial Distribution
  4. Exponential Distribution
  5. Bernoulli Distribution

Answers

1.1 Discrete, $[1,\infty)$, the number of collisions until two molecules react

2. Slicing Lists (6 Points)

Using this sentence: "The quick brown fox jumps over the lazy dog", Create slices of the string to answer the following questions. Note that character/element mean the same thing, so that every element in the sentence is a character. Answer in Python

  1. What is the first characeter?
  2. What is the sentence without the last characeter?
  3. What are the first 5 characeters?
  4. What is the first half of the sentence?
  5. What is the second half?
  6. What is every 3rd character, starting from the 4th?

Answers


In [2]:
#2.1
string = 'The quick brown fox jumps over the lazy dog'
print string[0]


T

3. Numpy Arrays and Arithmetic (12 Points)

  1. Create a numpy array containing a set of points between 0 and 30 spaced apart by 0.02. This should be done with a numpy function.
  2. Using a for loop, sum all the elements in the array and print the sum. Check your answer using the numpy sum function.
  3. Using the array from question 3.1, create an array representing a $\lambda = 3$ exponential distribution on the interval $[0,30)$. Note: the word lambda is a reserved word in python, meaning you cannot use it for a variable name. You can tell if a variable is reserved because it is a different color/font than other variables in ipython. Also, when applying mathematical functions to numpy arrays, you must use the numpy versions, for example numpy.cos instead of math.cos
  4. Using a for loop and the array from Question 3.1, compute the expected value of the exponential distribution. To evaluate the integral, use $\int f(x)dx = \sum_i f(x_i) \Delta x$, where $\Delta x$ is the spacing between your points and $f(x_i)$ is the function evaluated at point $x_i$. As you know, it should be $1/3$.
  5. Using both the arrays from Question 3.1 and 3.3 and the sum function from numpy, compute the expected value without a for loop.
  6. Using your equation from HW 2, problem 5 (see key), compute the expected value and variance of the sum of two dice

4. Plotting (4 Points)

  1. Create a numpy array of points and evaluate the exponential distribution on it. Plot it from $0$ to $2\lambda$.
  2. Do the same for the geometric distribution. Think carefully about whether it should be a line or a point plot and what the sample space of the distribution is.
  3. Plot the binomial distribution with $N=10$, $p=0.25$. To get a binomial coefficient for arrays, call from scipy.special import comb and use the comb(N, n) function, where n is your array.
  4. Plot the binomial distribution with $N=150$, $p=0.5$.

In [ ]: