(New page: 1. Generating uniformly distributed random numbers between 0 and 1: U(0,1) a) Using matlab functions The rand function returns uniformly distributed random numbers between 0 and 1. r = ...) |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | [[Category:bonus point project]] | |
+ | [[Category:ECE302]] | ||
+ | [[Category:probability]] | ||
− | + | <center><font size= 4> | |
+ | '''Methods of Generating Random Variables''' | ||
+ | </font size> | ||
− | + | Student project for [[ECE302]] | |
+ | |||
+ | by Zhenming Zhang | ||
+ | </center> | ||
+ | ---- | ||
+ | ---- | ||
+ | |||
+ | == 1. Generating uniformly distributed random numbers between 0 and 1: U(0,1) == | ||
+ | |||
+ | === a) Linear Congruential Generators === | ||
+ | A linear congruential generator has the property that numbers are generated according to | ||
+ | |||
+ | Zi = (aZ(i-1) + c) mod m | ||
+ | |||
+ | where m, a, c and Z0 are non-negative integers. We say that m is the modulus and that Z0 is the seed. The sequence that we obtain clearly satisfies 0<= Zi < m. In order to generate pseudo-random numbers, U1,...,Un,..., we set Ui = Zi/m. Note that Ui is inside(0,1) for each i. | ||
+ | |||
+ | We now act as though the Ui's constitute an independent sequence of U(0,1) random variables. | ||
+ | |||
+ | |||
+ | === b) Using MATLAB Functions === | ||
+ | |||
+ | rand(n) | ||
r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix. | r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix. | ||
Line 11: | Line 36: | ||
ans = 0.8147 0.9058 0.127 0.9134 0.6324 | ans = 0.8147 0.9058 0.127 0.9134 0.6324 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | == 2. Generating Normal Random variables == | ||
+ | |||
+ | ===a) Box-Muler method=== | ||
+ | |||
+ | If Z- N(0, I2) then | ||
+ | |||
+ | R=(Z1)^2 + (Z2)^2 is exponentially distributed with mean 2. | ||
+ | |||
+ | Given R, the point(Z1, Z2) is uniformly distributed on the circle of radius sqrt(R) centered at the origin. | ||
+ | |||
+ | Generate R and choose a point uniformly from the circle of radius sqrt(R). (r = -2log(U1)) | ||
+ | |||
+ | To generate a random point on a circle, generate a random angle uniformly between 0 and 2pi and map the angle to a point on the circle. | ||
+ | |||
+ | The random angle can be generated as V=2*pi*U2 and the corresponding point has coordinates (sqrt(R)*cos(V)), (sqrt(R)*sin(V)). | ||
+ | |||
+ | === b) Using MATLAB Functions === | ||
+ | |||
+ | normrnd(mu, sigma) | ||
+ | |||
+ | r=normrnd(mu, sigma) generates random numbers from the normal distribution with mean parameter mu and standard deviation parameter sigma. mu and sigma can be vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R. A scalar input for mu or sigma is expanded to a constant array with the same dimensions as the other input. | ||
+ | |||
+ | |||
+ | [[References:]] | ||
+ | |||
+ | Martin Haugh, 2004, " Generating Random Variables and Stochastic Process" | ||
+ | Retrieved from [http://www.columbia.edu/~mh2078/MCS04/MCS_generate_rv.pdf] | ||
+ | |||
+ | Ozgur KARAYALCIN, 2007, "Generating Random numbers and Random variables", | ||
+ | Retrieved from [http://www.mathematik.uni-kl.de/~seifried/eng/teaching/teach_07ws/ozgur.pdf] | ||
+ | |||
+ | MathWorks Reference | ||
+ | Retrieved from [http://www.mathworks.com/index.html] | ||
+ | |||
+ | ---- | ||
+ | [[2013_Spring_ECE_302_Boutin|Back to ECE302 Spring 2013, Prof. Boutin]] |
Latest revision as of 09:05, 17 April 2013
Methods of Generating Random Variables
Student project for ECE302
by Zhenming Zhang
Contents
1. Generating uniformly distributed random numbers between 0 and 1: U(0,1)
a) Linear Congruential Generators
A linear congruential generator has the property that numbers are generated according to
Zi = (aZ(i-1) + c) mod m
where m, a, c and Z0 are non-negative integers. We say that m is the modulus and that Z0 is the seed. The sequence that we obtain clearly satisfies 0<= Zi < m. In order to generate pseudo-random numbers, U1,...,Un,..., we set Ui = Zi/m. Note that Ui is inside(0,1) for each i.
We now act as though the Ui's constitute an independent sequence of U(0,1) random variables.
b) Using MATLAB Functions
rand(n)
r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix.
Example: rand(1, 5)
ans = 0.8147 0.9058 0.127 0.9134 0.6324
2. Generating Normal Random variables
a) Box-Muler method
If Z- N(0, I2) then
R=(Z1)^2 + (Z2)^2 is exponentially distributed with mean 2.
Given R, the point(Z1, Z2) is uniformly distributed on the circle of radius sqrt(R) centered at the origin.
Generate R and choose a point uniformly from the circle of radius sqrt(R). (r = -2log(U1))
To generate a random point on a circle, generate a random angle uniformly between 0 and 2pi and map the angle to a point on the circle.
The random angle can be generated as V=2*pi*U2 and the corresponding point has coordinates (sqrt(R)*cos(V)), (sqrt(R)*sin(V)).
b) Using MATLAB Functions
normrnd(mu, sigma)
r=normrnd(mu, sigma) generates random numbers from the normal distribution with mean parameter mu and standard deviation parameter sigma. mu and sigma can be vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R. A scalar input for mu or sigma is expanded to a constant array with the same dimensions as the other input.
Martin Haugh, 2004, " Generating Random Variables and Stochastic Process" Retrieved from [1]
Ozgur KARAYALCIN, 2007, "Generating Random numbers and Random variables", Retrieved from [2]
MathWorks Reference Retrieved from [3]