# Classes - Beard

You are here: start » ee370homework

-

### Homework 1

From Bertsekas and Tsitsiklis, Introduction to Probability, 2nd Ed.

1. Chapter 1 Problem 1.
2. Chapter 1 Problem 2.
3. Chapter 1 Problem 5.
4. Chapter 1 Problem 6.
5. Chapter 1 Problem 7.
6. Find a computer that you will be able to use throughout the semester and launch MATLAB. Spend 15 minutes playing around and typing expressions into the command window such as 2+2 and rand (which will be very important in the future). Run the commands help rand to see how the help works. Set a variable r = rand([100, 1]) and plot the values stem® . Run the bench command and report the relative speed of your machine. Learn how to print the results to a printer.

### Homework 2

1. Chapter 1 Problem 14. (Bertsekas)
2. Chapter 1 Problem 15. (Bertsekas)
3. Chapter 1 Problem 16. (Bertsekas)
4. Chapter 1 Problem 17. (Bertsekas)
5. Chapter 1 Problem 20. (Bertsekas)
6. Chapter 1 Problem 25. (Bertsekas)
7. Chapter 1 Problem 26. (Bertsekas)
8. A company producing electric relays has three manufacturing plants producing 50, 30, and 20 percent, respectively of its product. Suppose that the probabilities that a relay manufactured by these plants is defective are 0.02, 0.05, and 0.01, respectively.
1. If a relay is selected at random from the output of the company, what is the probability that it is defective?
2. If a relay selected at random is found to be defective, what is the probability that it was manufactured by plant 2?
9. MATLAB Problem. The objective of this problem is to learn to use scripts and functions. Download continuous_sim.m and copy it into the working matlab directory and run the script by typing continuous_sim in MATLAB. You will see that it simulates 100 random points in a box of dimension 1 by 1. Modify the code so that you can find the probability of the points falling within a circle of radius 0.5 centered at (0.5, 0.5). Calculate the probability both analytically, and with your modi fied code. Run it for 1000 and 10,000 points. Turn in your analytical solution, code, and figure that shows 10,000 points.

### Homework 3

1. Chapter 1 Problem 31. (Bertsekas)
2. Chapter 1 Problem 34. (Bertsekas)
3. Chapter 1 Problem 35. (Bertsekas)
4. Chapter 1 Problem 36. (Bertsekas)
5. Chapter 1 Problem 37. (Bertsekas)
6. Chapter 1 Problem 53. (Bertsekas)
7. Chapter 1 Problem 59. (Bertsekas)
8. Consider the probabilities associated with a major earthquake hitting the San Francisco Bay Region as determined by the US Geological Survey (http://earthquake.usgs.gov/regional/nca/wg02/results.php). You live in San Jose and are considering building a factory there. Assume that the earthquake events are independent. What is the probability that between 2003-2032 you will get hit with at least one major earthquake along the San Andreas Fault or the Calaveras Fault? What is the probability that between 2003-2032 you do not get hit by an earthquake along the San Andreas Fault nor the Calveras Fault but you do get hit by at least one major earthquake along the Hayward Fault? In reality, is it plausible to assume that these earthquake events are independent?
9. MATLAB Problem. You have been hired by Coin Flips 'R' Us to investigate a possible case of fraud. The company has gotten sequences of coin fl ips from 6 di fferent outsourced companies. Management suspects that some of the companies aren't actually flipping fair coins but are using some other procedure. The sequences (of varying lengths) are found on the web with the homework. Your quest is to determine which sequences were generated using fair coin flips and which were generated in some other fashion. sequences
1. Hint: To accomplish the goal, consider the probabilities of getting 1 head, then 2 heads in a row, 3 heads in a row, 4 heads in a row, and 5 heads in a row. Then compute the statistics for each sequence. You can do a simple statistic of two heads in a row using the following code: p_2 = sum ( 1 == conv ( 1 / 2 * [ 1 1 ] , t e s t_ s e q u e n c e ) ) / N. Develop MATLAB code to compute the statistics for each sequence. Turn in your code, the head count statistics for each sequence, and which sequences you suspect are fraudulent.

### Homework 4

1. Chapter 2 Problem 1.
2. Chapter 2 Problem 4.
3. Chapter 2 Problem 5.
4. Chapter 2 Problem 6.
5. Chapter 2 Problem 12.
6. Chapter 2 Problem 13.
7. Chapter 2 Problem 14.
8. Chapter 2 Problem 15.
9. MATLAB Problem. In this example you will learn about how to simulate various random variables in MATLAB. So far, we have actually used a pseudo-continuous random variable through the rand command. You can also generate the discrete random variables that we use in ECEn 370 through the random command. Type help random at the MATLAB prompt to read more information about the random command. For example, you can type random('Binomial', 10, 0.6, 10, 1) to simulate a Binomial random variable with n=10, p=0.6, in a vector of length 10. You can do this for 'Binomial', 'Poisson', and 'Geometric' random variables. One way to visualize the probability mass function of the distribution is the following code:

trials = 10000;
X_vector = random ( 'Binomial' , 10 , 0.6 , 1 , trials );
for i =1:11 % 'for' loops in matlab can't start at 0
count ( i , 1 ) = i-1 ;
count ( i , 2 ) = sum ( ( i-1 ) == X_vector ) ;
end
bar ( count ( : , 1 ) , count ( : , 2 ) / trials ) ;
Simulate and plot the probability mass functions for the following random variables:

1. Binomial with parameters n = 20 and p = 0.2 (you will need more bins in your histogram)
2. Geometric random variable with parameter p = 0.1 (choose reasonable number of bins). Note that they define the geometric as the number of failures after a success which is why you can get zero.
3. Poisson random variable with parameter = 3

Imagine now that you have a binomial random variable, X1, defined by parameters n=3, p=1/4. Imagine that you have another binomial random variable, X2, defined by parameters n=4, p=1/2. Now define the function Y = X1 + X2. What is the probability mass function for Y ? Simulate and plot the random variables X1, X2, and Y in MATLAB. Does simulation of the PMF of Y compare well with the probability mass function you computed analytically?

### Homework 5

1. Bertsekas, Chapter 2 Problem 16
2. Bertsekas, Chapter 2 Problem 17.
3. Bertsekas, Chapter 2 Problem 20.
4. Bertsekas, Chapter 2 Problem 24.
5. Bertsekas, Chapter 2 Problem 26.
6. Bertsekas, Chapter 2 Problem 31.
7. Let X be a Poisson R.V. with parameter . Find the conditional pmf of X given B = (X is even)
8. Bertsekas, Chapter 2 Problem 34.
9. Please download the file associated with this homework and put them into your working directory when you do this problem. The file “simulate_joint_PMF.m” is necessary for “HW5_prob_example.m” to work correctly.

Read through “HW5_prob_example.m” and execute it so you can see how a joint PMF can be described in terms of matrices, simulated, and visualized. You have been employed by McTacoKing to do an analysis of their customer purchasing habits. They have given you data on 10,000 normal customers: X is the number of burgers each ordered,and Y is the number of servings of fries. All normal customers order at least one burger and at least one serving of fries. For all normal customers, the maximum number of burgers is six and the maximum number of fries is four. This data is given to you as a “burgerfry.mat” file that you must load which contains the variable “outcomes” which has the customer data. homework-5.zip

• 9.a First, plot the estimated joint PMF of the burger/fry data as a 3-dimensional X, Y graph as shown in the example code. Turn in your plot and the corresponding matrix. This will serve as the actual PMF for the rest of the problem.
• 9.b What is the probability that a normal customer will buy three burgers and two servings of fries?
• 9.c What is the marginal PMF for the number of burgers a normal customer will buy? Plot this and turn it in.
• 9.d What is the marginal PMF for the number of fries servings a normal customer will buy? Plot this and turn it in.
• 9.e What is the expected number of burgers that a normal customer will buy?
• 9.f What is the expected number of fries servings that a normal customer will buy?
• 9.g If burgers cost $2.00 and fries servings cost$1.00, what is the expected amount of money that you will obtain from each normal customer?
• 9.h If a normal customer buys two fries servings, what is the PMF of the number of burgers that he will buy? Plot this and turn it in.

### Homework 6

1. The joint pmf of a bivariate r.v. (X, Y) is given by where k is a constant. (a) Find the value of k. that makes this a valid pmf. (b) Find the marginal pmf's of X and Y. © Are X and Y independent?

2. Bertsekas, Chapter 2 Problem 38.

3. Bertsekas, Chapter 2 Problem 39.

4. Bertsekas, Chapter 2 Problem 40.

5. Bertsekas, Chapter 2 Problem 41.

6. Bertsekas, Chapter 3 Problem 1.

7. Bertsekas, Chapter 3 Problem 2.

8. Assume that the length of a phone call in minutes is an exponential r.v. X with parameter  .

If someone arrives at a phone booth just before you arrive, find the probability that you will have to wait (a) less than 5 minutes, and (b) between 5 and 10 minutes.

9. MATLAB Problem. Adapted from Kay. Expectation and Conditioning of Discrete Random Variables. There are many different ways to simulate joint random variables. We will explore two approaches in this problem. Consider that you have the following joint PMF, :   1/8 1/8 1/4 1/2

One way to simulate this is to break up a unit interval and for those values between 0 and 1/8, you choose (0,0), for values between 1/8 and 2/8, you choose (1,0), for values between 2/8 and 4/8 you choose (0,1), and for values between 4/8 and 1, you choose (1,1). This is one big if statement.

• (9.a) Write a MATLAB script that performs this approach. Simulate it for 10000 repititions and see if

the ratios match the probabilities. Another approach to this problem is to use conditioning. First, determine the marginal PMF, .

Then determine the conditional PMF, .

To simulate you first determine an x by splitting up the uniform random variable. Then given that x, you determine a y by simulating the conditional PMF. Essentially you perform two components of the experiment sequentially. However, in this case you are doing it without knowledge of the entire joint PMF.

• (9.b) Write a MATLAB script that performs this second approach. Simulate it for 10000 repititions and make sure that it matches part a and the original joint PMF.
• (9.c) Calculate the expectation of X analytically. Then take the average of the results from your marginal PMF that you simulated above. Does the expectation of X match the average of the results from your marginal PMF.
• (9.d) Calculate the variance of X analytically. Then calculate the variance of the results from your marginal PMF that you simulated above. Does the variance of X match the simulated variance?

### Homework 7

1. The pdf of a continuous r.v. X is given by Find the corresponding cdf, and sketch pdf and cdf.

2. Bertsekas, Chapter 3 Problem 5.

3. Bertsekas, Chapter 3 Problem 6.

4. Bertsekas, Chapter 3 Problem 7.a

An example of this type of problem is in continuous_sim_commented. One way to do this is to simulate a uniform distribution over a circle of radius 1 and then compute the distance to the point:

• 4.1: define a circle with radius of 1 centered at (0, 0),
• 4.2: generate uniform random variables square defined by (-1,-1),(-1,1),(1,1), and (-1,1),
• 4.3: only accept points that fall in the circle which is equivalent to making sure that all the darts hit within the target,
• 4.4: compute the distances from the center as the values of your random variable.

Do this simulation for 10,000 points and see if the distribution matches the PDF, the mean, and the variance you calculated in part a. Turn in your code, plots, and calculations.

5. Bertsekas, Chapter 3 Problem 9

6. Bertsekas, Chapter 3 Problem 10
Implement part b in MATLAB (look at the solution) to show how you can use this to generate the exponential random variable. Simulate this for 10,000 points and turn in your histogram plot. It should look like the histogram for an exponential random variable.

7. Bertsekas, Chapter 3 Problem 11

8. Bertsekas, Chapter 3 Problem 12

9. Bertsekas, Chapter 3 Problem 13

### Homework 8

1. Bertsekas and Tsitsiklis, 4.1
2. Bertsekas and Tsitsiklis, 4.3
3. Bertsekas and Tsitsiklis, 4.4
4. Bertsekas and Tsitsiklis, 4.5
5. Bertsekas and Tsitsiklis, 4.6
6. Bertsekas and Tsitsiklis, 4.8
7. Bertsekas and Tsitsiklis, 4.12
8. Bertsekas and Tsitsiklis, 4.18
9. Bertsekas and Tsitsiklis, 4.19

### Homework 9

1. Bertsekas and Tsitsiklis, 4.22
2. Bertsekas and Tsitsiklis, 4.23
3. Bertsekas and Tsitsiklis, 4.24
4. Bertsekas and Tsitsiklis, 4.29
5. Bertsekas and Tsitsiklis, 4.30
6. Bertsekas and Tsitsiklis, 4.33
7. Bertsekas and Tsitsiklis, 4.35
8. Bertsekas and Tsitsiklis, 4.41
9. Bertsekas and Tsitsiklis, 4.43

### Homework 11 