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:
Random matrix/normal distribution

Subject: Random matrix/normal distribution

From: Michael Grosswald

Date: 29 Sep, 2009 20:07:02

Message: 1 of 5

I'm trying to generate random matrices whose entries are from the normal distribution.

Something like this:

(1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)

Isn't going to work because squaring a matrix doesn't square each entry. How can I correct this or am I going about this the wrong way.

I'm still a MATLAB beginner so go easy on me!

Subject: Random matrix/normal distribution

From: dpb

Date: 29 Sep, 2009 20:09:13

Message: 2 of 5

Michael Grosswald wrote:
> I'm trying to generate random matrices whose entries are from the normal distribution.
>
> Something like this:
>
> (1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)
>
> Isn't going to work because squaring a matrix doesn't square each
> entry. How can I correct this or am I going about this the wrong way.

> I'm still a MATLAB beginner so go easy on me!


Well,

lookfor normal

returns

 >> lookfor normal
RANDN Normally distributed random numbers.
...
SPRANDN Sparse normally distributed random matrix.
...

which might look interesting... :)

As for the question on squaring terms in an array (or vector), look at
".*" instead of "*"

--

Subject: Random matrix/normal distribution

From: Doug Hull

Date: 29 Sep, 2009 20:14:02

Message: 3 of 5

A .^ 2

This will take your matrix and square it element by element.

.* is similar.

Doug

"Michael Grosswald" <michaelgrosswald@yahoo.co.uk> wrote in message <h9tpd6$bh9$1@fred.mathworks.com>...
> I'm trying to generate random matrices whose entries are from the normal distribution.
>
> Something like this:
>
> (1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)
>
> Isn't going to work because squaring a matrix doesn't square each entry. How can I correct this or am I going about this the wrong way.
>
> I'm still a MATLAB beginner so go easy on me!

Subject: Random matrix/normal distribution

From: Michael Grosswald

Date: 29 Sep, 2009 21:20:04

Message: 4 of 5

Thanks a lot to both of you.

Subject: Random matrix/normal distribution

From: Tom Lane

Date: 30 Sep, 2009 14:32:19

Message: 5 of 5

> I'm trying to generate random matrices whose entries are from the normal
> distribution.
>
> Something like this:
>
> (1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)
>
> Isn't going to work because squaring a matrix doesn't square each entry.
> How can I correct this or am I going about this the wrong way.

Michael, if you square the matrix, this will give you values of the normal
density function evaluated at random points. I encourage you to try the
advice from dbp instead of squaring the matrix in this formula.

-- Tom

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