

CS381  Lab 5: Monte Carlo Integration
Fall Quarter 1999
Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor
S331, 2777339
www.msoe.edu/~taylor/
Purpose
The purpose of this lab assignment is to gain an appreciation of how
statistical techniques can be used to solve deterministic problems.
Background
One common type of random number generator is the linear congruential
random number generator (LCRNG). It may be defined recursively as:
x_{n+1} = (a x_{n} + c) mod m.
The ability of the random number generator is highly dependent on the
constants a, c, and m and the initial condition x_{0} (aka, the
seed).
Assignment
In this lab, you are to do the following:
 Implement a linear congruential random number generator.
 Experiment with different values for the constants. In one of
your tests, use a=16807, c=0, m=2^{31}1, and
x_{0}=667790.
 Speculate on the role of the different constants. How does the
choice of each change the characteristics of the numbers generated?
 Use the generalized Monte Carlo method described in class to integrate
the following functions:
 f(x) = sin(x), for x in [0, ]
 f(x) = 4x/(1 + x^{2})^{2}, for x in [1.5,1.5]
 f(x) = (2/(1 + x^{2}))  x^{2}, for x in [1,1]
You should calculate these integrals using your LCRNG and
cstdlib's rand() function. Be sure to comment on any
differences.
 10% of your grade for this assignment will be based on the design of
your program. A simple objectoriented program design
is desirable.
Formatting Notes
 When discussing the results of your experiments with the linear
congruential random number generator, you may find it useful to
include graphs. These graphs should be included as separate files
and follow these guidelines:
 The three f(x)'s may be included in your report using the following
commands:
\[ f(x) = \sin(x), \qquad \mbox{ for } x \in [0, \pi] \]
\[ f(x) = \frac{4x}{(1 + x^2)^2} \qquad
\mbox{ for } x \in [1.5, 1.5] \]
\[ f(x) = \frac{2}{1 + x^2}  x^2 \qquad
\mbox{ for } x \in [1, 1] \]
 The update equation for the LC random number generator can be written as:
$x_{n+1} = (a x_n + c) \mbox{ mod } m$
For this project, you may work individually or with a
partner.
Lab report (due midnight Tuesday, October 26, 1999)
This week, your lab report need not be selfcontained. If you worked with
a partner, only one report is required for the two of you. Your report should
include:
 Discussion containing:
 A brief description of any problems you encountered and how they were
resolved
 A brief description of your design plan
 A brief description of your approach for answering the questions
(along with your answers)
 Any questions you have regarding the lab
 Suggestions for how the lab could be improved in the future
 Documented source code
 The data files that you created as well as their corresponding
output
As with any report you submit, correct spelling and grammar are
required. In addition, your report should be submitted electronically
following the Electronic Submission
Guidelines. (You may wish to consult the
sample report before submitting your
report.) Be sure to keep copies of all your files, in case something
gets lost. It may be wise to keep a diskette backup as well.
If you have any questions, consult the instructor.
This page was created by Dr.
Christopher C. Taylor, copyright 1999.
