Got Questions? Get Answers.
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:
zero mean random numbers

Subject: zero mean random numbers

From: Alessio Nervi

Date: 12 Jan, 2011 15:43:05

Message: 1 of 9

Hello

I would like to generate random numbers with specific properties.

One property of this random numbers is to have zero mean. This is my problem.
How can I generate zero mean random numbers?

Thanks in advance for the help

Alessio

Subject: zero mean random numbers

From: I am too much me

Date: 12 Jan, 2011 15:49:16

Message: 2 of 9

On 12/01/11 9:43 AM, Alessio Nervi wrote:

> How can I generate zero mean random numbers?

randn()

Subject: zero mean random numbers

From: James Tursa

Date: 12 Jan, 2011 15:53:05

Message: 3 of 9

"Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <igki68$a9q$1@fred.mathworks.com>...
> Hello
>
> I would like to generate random numbers with specific properties.
>
> One property of this random numbers is to have zero mean. This is my problem.
> How can I generate zero mean random numbers?
>
> Thanks in advance for the help
>
> Alessio

Subtract the mean of the underlying distribution. e.g.,

rand(n,1) - 0.5

or

randn(n,1)

If you read the doc for rand and randn it gives related examples.

James Tursa

Subject: zero mean random numbers

From: Sean de

Date: 12 Jan, 2011 15:56:04

Message: 4 of 9

"Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <igki68$a9q$1@fred.mathworks.com>...
> Hello
>
> I would like to generate random numbers with specific properties.
>
> One property of this random numbers is to have zero mean. This is my problem.
> How can I generate zero mean random numbers?
>
> Thanks in advance for the help
>
> Alessio

Just subtract the mean...

A = rand(10);
A = A - mean(A(:));
mean(A(:))

Subject: zero mean random numbers

From: Alessio Nervi

Date: 12 Jan, 2011 16:05:05

Message: 5 of 9

"James Tursa" wrote in message <igkip1$h7n$1@fred.mathworks.com>...
> "Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <igki68$a9q$1@fred.mathworks.com>...
> > Hello
> >
> > I would like to generate random numbers with specific properties.
> >
> > One property of this random numbers is to have zero mean. This is my problem.
> > How can I generate zero mean random numbers?
> >
> > Thanks in advance for the help
> >
> > Alessio
>
> Subtract the mean of the underlying distribution. e.g.,
>
> rand(n,1) - 0.5
>
> or
>
> randn(n,1)
>
> If you read the doc for rand and randn it gives related examples.
>
> James Tursa

Thanks for the help, I read the doc and I found in example, but in my case i should add 0, and the random numbers genrated have not zero mean.
My code is:

x=rand(1000,1)+0
or

x=rand(1000,1)-0

Thanks

Alessio

Subject: zero mean random numbers

From: Alessio Nervi

Date: 12 Jan, 2011 18:49:06

Message: 6 of 9

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <igkiuk$sd2$1@fred.mathworks.com>...
> "Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <igki68$a9q$1@fred.mathworks.com>...
> > Hello
> >
> > I would like to generate random numbers with specific properties.
> >
> > One property of this random numbers is to have zero mean. This is my problem.
> > How can I generate zero mean random numbers?
> >
> > Thanks in advance for the help
> >
> > Alessio
>
> Just subtract the mean...
>
> A = rand(10);
> A = A - mean(A(:));
> mean(A(:))

Thanks Sean!! I undestand!Thanks!!

Subject: zero mean random numbers

From: Steven_Lord

Date: 13 Jan, 2011 04:27:11

Message: 7 of 9



"Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message
news:igkjfh$3po$1@fred.mathworks.com...
> "James Tursa" wrote in message <igkip1$h7n$1@fred.mathworks.com>...
>> "Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message
>> <igki68$a9q$1@fred.mathworks.com>...

*snip*

> Thanks for the help, I read the doc and I found in example, but in my case
> i should add 0,

Incorrect.

> and the random numbers genrated have not zero mean.
> My code is:
>
> x=rand(1000,1)+0

RAND generates numbers from the uniform distribution on (0, 1). Why do you
believe that the mean of the uniform distribution on the interval (0, 1) is
0?

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: zero mean random numbers

From: Alessio Nervi

Date: 13 Jan, 2011 07:59:04

Message: 8 of 9

"Steven_Lord" <slord@mathworks.com> wrote in message <igluuv$6v8$1@fred.mathworks.com>...
>
>
> "Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message
> news:igkjfh$3po$1@fred.mathworks.com...
> > "James Tursa" wrote in message <igkip1$h7n$1@fred.mathworks.com>...
> >> "Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message
> >> <igki68$a9q$1@fred.mathworks.com>...
>
> *snip*
>
> > Thanks for the help, I read the doc and I found in example, but in my case
> > i should add 0,
>
> Incorrect.
>
> > and the random numbers genrated have not zero mean.
> > My code is:
> >
> > x=rand(1000,1)+0
>
> RAND generates numbers from the uniform distribution on (0, 1). Why do you
> believe that the mean of the uniform distribution on the interval (0, 1) is
> 0?
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

I understand my error Steve. The mean is not zero, but if I subtract the mean to random numbers, I get zero mean random numbers

Thanks

Alessio

Subject: zero mean random numbers

From: Peter Perkins

Date: 13 Jan, 2011 16:59:14

Message: 9 of 9

On 1/12/2011 10:43 AM, Alessio Nervi wrote:
> One property of this random numbers is to have zero mean.

Alessio, you've gotten two different types of responses. One advises
you to generate numbers, and subtract their sample mean. The other
advises you to generate numbers, and subtract the theoretical mean of
the distribution that the were drawn from (which may be zero).

You need to decide if you want

1) a vector of random values that has mean zero, or
2) a vector of random values that is drawn from a zero-mean distribution.

Hope this helps.

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