Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random Numbers with Gaussian and Uniform Distributions in matlab

I want generate a number in Gaussian and Uniform distributions in matlab. I know this function randi and rand() but all of them are in normal (Gaussian) distribution. How can a generate a random number in uniform distribution?

like image 327
Yuseferi Avatar asked Dec 12 '12 17:12

Yuseferi


People also ask

How do you generate a random number using the Gaussian distribution in MATLAB?

r = normrnd( mu , sigma ) generates a random number from the normal distribution with mean parameter mu and standard deviation parameter sigma . r = normrnd( mu , sigma , sz1,...,szN ) generates an array of normal random numbers, where sz1,...,szN indicates the size of each dimension.

How do you get uniform random numbers in MATLAB?

X = rand( sz ) returns an array of random numbers where size vector sz defines size(X) . For example, rand([3 4]) returns a 3-by-4 matrix. X = rand(___, typename ) returns an array of random numbers of data type typename . The typename input can be either "single" or "double" .

How do you generate random numbers from a uniform distribution?

The inversion method relies on the principle that continuous cumulative distribution functions (cdfs) range uniformly over the open interval (0,1). If u is a uniform random number on (0,1), then x = F - 1 ( u ) generates a random number x from any continuous distribution with the specified cdf F .


2 Answers

Use rand(dimensions) for a Uniform Distribution between 0 and 1.

Use randn(dimensions) * sqrt(sigma) + mu for a Gaussian Distribution with a mean of mu and standard deviation of sigma.

Uniform Distribution

Normal Distribution

like image 93
supyo Avatar answered Oct 07 '22 04:10

supyo


randn is the function to generate Gaussian distributed variables (randi and rand produce uniformly distributed ones).

like image 30
Jonas Avatar answered Oct 07 '22 05:10

Jonas