Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to generate a gaussian distribution using random number generator

Subject: how to generate a gaussian distribution using random number generator

From: faraz.a

Date: 3 Jul, 2013 23:52:09

Message: 1 of 7

i want to generate 50,000 samples according to the gaussian distribution using random number generator where sigma=1 and mean=0
X is a normally distributed random variable N(0,?2). mean=0 variance=1

I did this
R=randn(50000)

i got an error

Error using randn
Out of memory. Type HELP MEMORY for your options.

and if i am using
R=randn(50000,1);
hist(R)

this generated a distribution but the y label was ranging from -4 to 5. I want it from -infinity to +infinity

how to do that?

Subject: how to generate a gaussian distribution using random number generator

From: dpb

Date: 4 Jul, 2013 00:40:24

Message: 2 of 7

On 7/3/2013 6:52 PM, faraz.a wrote:
> i want to generate 50,000 samples according to the gaussian distribution
> using random number generator where sigma=1 and mean=0 X is a normally
> distributed random variable N(0,?2). mean=0 variance=1
>
> I did this R=randn(50000)
>
> i got an error
>
> Error using randn
> Out of memory. Type HELP MEMORY for your options.

doc randn

You tried to generate 50K x 50K array which is ~19 GB

> and if i am using R=randn(50000,1);
> hist(R)
>
> this generated a distribution but the y label was ranging from -4 to 5.
> I want it from -infinity to +infinity
> how to do that?

What's the probability of getting either extreme from a sample from a
standard normal distribution?

For that matter, what's the probability of |z|>5? How does that compare
w/ the size of the sample generated?

--

Subject: how to generate a gaussian distribution using random number generator

From: dpb

Date: 4 Jul, 2013 00:48:27

Message: 3 of 7

On 7/3/2013 6:52 PM, faraz.a wrote:
> i want to generate 50,000 samples according to the gaussian distribution
> using random number generator where sigma=1 and mean=0 X is a normally
> distributed random variable N(0,?2). mean=0 variance=1
>
> I did this R=randn(50000)
>
> i got an error
>
> Error using randn
> Out of memory. Type HELP MEMORY for your options.

doc randn

You tried to generate 50K x 50K array which is ~19 GB

> and if i am using R=randn(50000,1);
> hist(R)
>
> this generated a distribution but the y label was ranging from -4 to 5.
> I want it from -infinity to +infinity
> how to do that?

What's the probability of getting either extreme from a sample from a
standard normal distribution?

For that matter, what's the probability of |z|>5? How does that compare
w/ the size of the sample generated?

--

Subject: how to generate a gaussian distribution using random number generator

From: TideMan

Date: 4 Jul, 2013 19:44:26

Message: 4 of 7

On Thursday, July 4, 2013 12:40:24 PM UTC+12, dpb wrote:
> On 7/3/2013 6:52 PM, faraz.a wrote:
>
> > i want to generate 50,000 samples according to the gaussian distribution
>
> > using random number generator where sigma=1 and mean=0 X is a normally
>
> > distributed random variable N(0,?2). mean=0 variance=1
>
> >
>
> > I did this R=randn(50000)
>
> >
>
> > i got an error
>
> >
>
> > Error using randn
>
> > Out of memory. Type HELP MEMORY for your options.
>
>
>
> doc randn
>
>
>
> You tried to generate 50K x 50K array which is ~19 GB
>
>
>
> > and if i am using R=randn(50000,1);
>
> > hist(R)
>
> >
>
> > this generated a distribution but the y label was ranging from -4 to 5.
>
> > I want it from -infinity to +infinity
>
> > how to do that?
>
>
>
> What's the probability of getting either extreme from a sample from a
>
> standard normal distribution?
>
>
>
> For that matter, what's the probability of |z|>5? How does that compare
>
> w/ the size of the sample generated?
>
>
>
> --

In fact, the answer to your question, dpb, is:
sqrt(2*log(N))*sigma
which is the expected maximum of N Gaussian distributed numbers having standard deviation sigma.
It's called the Universal Threshold.

Subject: how to generate a gaussian distribution using random number generator

From: dpb

Date: 4 Jul, 2013 21:03:52

Message: 5 of 7

On 7/4/2013 2:44 PM, TideMan wrote:
> On Thursday, July 4, 2013 12:40:24 PM UTC+12, dpb wrote:
...

>> For that matter, what's the probability of |z|>5? How does that compare
>> w/ the size of the sample generated?
...

> In fact, the answer to your question, dpb, is:
> sqrt(2*log(N))*sigma
> which is the expected maximum of N Gaussian distributed numbers
> having standard deviation sigma. It's called the Universal
> Threshold.

Yeah, but why confuse OP w/ facts...??? :)

--

Subject: how to generate a gaussian distribution using random number generator

From: dpb

Date: 4 Jul, 2013 22:21:22

Message: 6 of 7

On 7/4/2013 4:03 PM, dpb wrote:
> On 7/4/2013 2:44 PM, TideMan wrote:
>> On Thursday, July 4, 2013 12:40:24 PM UTC+12, dpb wrote:
> ...
>
>>> For that matter, what's the probability of |z|>5? How does that compare
>>> w/ the size of the sample generated?
> ...
>
>> In fact, the answer to your question, dpb, is:
>> sqrt(2*log(N))*sigma
>> which is the expected maximum of N Gaussian distributed numbers
>> having standard deviation sigma. It's called the Universal
>> Threshold.
>
> Yeah, but why confuse OP w/ facts...??? :)

Actually, what I was really trying to do was to goad OP into typing in

 >> 1/normpdf(5)
ans =
    6.7262e+05
 >>

and hoping that would open some eyes. Faint hope, that, I know... :(

--

Subject: how to generate a gaussian distribution using random number generator

From: Steven_Lord

Date: 8 Jul, 2013 18:10:48

Message: 7 of 7



"faraz.a " <syedfarazahmed@yahoo.com> wrote in message
news:kr2df9$7cq$1@newscl01ah.mathworks.com...
> i want to generate 50,000 samples according to the gaussian distribution
> using random number generator where sigma=1 and mean=0 X is a normally
> distributed random variable N(0,?2). mean=0 variance=1
>
> I did this R=randn(50000)
>
> i got an error
>
> Error using randn
> Out of memory. Type HELP MEMORY for your options.

As dpb said, you're trying to create a 50k-by-50k matrix. You don't have a
contiguous block of memory large enough to hold that.

> and if i am using R=randn(50000,1);
> hist(R)
>
> this generated a distribution but the y label was ranging from -4 to 5. I
> want it from -infinity to +infinity

Since you don't have an infinitely wide screen (even Weird Al Yankovic's
friend Frank only had a 2000 inch TV) it's going to be difficult for you to
plot an infinitely long line. If you want to "cheat" you could simply
relabel the first and last last points in the axes with -Inf and Inf. See
the example on this page for how to do that.

http://www.mathworks.com/help/matlab/creating_plots/setting-axis-parameters.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us