CS 547: Computer System Modeling Fundamentals

Fall 2000

Assignment 5: Random Variables

Due: Tuesday, October 16 at 5pm


  1. Using C, C++, or Java, write a function (or method) called "ExponentialRNG" that has a floating point input parameter called "rate" and returns a sample of from the exponential distribution with rate (lambda) equal to the value of the input parameter. Your ExponentialRNG should use a reliable uniform random number generator, such as the Unix random() function or the Java Random class.

    Create some code to test your ExponentialRNG(rate) function. In particular, have your test code call your ExponentialRNG function a large number of times with the same input parameter and calculate the mean, variance, and coefficient of variation of the samples returned. Note that you can compute the mean by keeping the sum of the samples and you can compute the variance by keeping a sum of the square of each sample.

    Turn in a listing of your ExponentialRNG and of your test function. Also turn in the measures that your test code computed after calling ExponentialRNG 100,000 times, and after calling ExponentialRNG only 10 times.

    Solution:

    Sample programs written in Java and C++ can be found at the following links:

    java
    C++
    Sample Output

  2. Is the following function a valid CDF?

        F(x) = 0,           x < 0
             = (1/9) x**2,  0 <= x <= 3
             = 1,           x > 3. 
    

    Solution:

    Yes. It satisfies the three conditions for a valid CDF, namely:
    F(-infinity) = F(0) = (1/9)*0**2 = 0,
    F(infinity) = F(3) = (1/9)* 3**2 = 1,
    and F is monotonically nondecreasing.

  3. Is each of the following a valid pdf? Why or why not?
    (a) f(x) = 2x, 0 <= x <= 0.5

    Solution:

    integral of 2x evaluated from 0 to 0.5 = 0.25
    assume f(x) = 0 for x<0 and f(x)=0 for x>0.5
    Not a valid pdf because the integral of f(x) from -infinity to +infinity is not equal to 1.

    (b) f(x) = e**(-4x) + 1.5e**(-2x), x >= 0

    Solution:

    integral of e**(-4x) + 1.5e**(-2x) from 0 to infinity = 1.0
    assume f(x)=0 for x<0.
    Is a valid pdf because the integral of f(x) from -(infinity) to infinity is 1.0.

  4. Consider a random variable X that is exponentially distributed with parameter lambda. Let Xbar be the mean or average value of X. What is the probability that X is less than or equal to 2*Xbar?

    Solution:

    Xbar = 1 / lambda
    P(X <= 2*Xbar) = 1 - e**[-lambda(2/lambda)] = 1 - 1/(e**2) = approx. 86.5%

  5. The probability density function of the rainfall in a given region is given by f(x) = 0.02x, for 0 <= x <= 10. Calculate the average amount of rainfall in the region.

    Solution:

    Xbar = integral(x * f(x))dx
    Xbar = integral from 0 to 10(x * 0.02x)dx
    Xbar = 6.67


vernon@cs.wisc.edu