Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Normally Distributed Random Matrix

2 views
Skip to first unread message

amitso...@gmail.com

unread,
Jun 12, 2007, 1:33:49 AM6/12/07
to
Hi,

I want to create a normally distributed random matrix in Mathematica.
I'm using the following code in Mathematica 5.2:

------------- code -----------------------------
<< Statistics`NormalDistribution`
n = 500;
A = RandomArray[NormalDistribution[], {n, n}]
------------------------------------------------

But it is not working even though it worked when I did it earlier on
Linux. When I enter A it just gives:

------------------------------------------------
A
RandomArray[NormalDistribution[], {500, 500}]
------------------------------------------------

Can anyone help me with this?

Thank you,
Amit


dimitris

unread,
Jun 13, 2007, 7:20:32 AM6/13/07
to
Did you load the package surely?

Quit[];

<< Statistics`NormalDistribution`

<<Statistics`NormalDistribution`

n=50;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0. Second,{{1.11234,-0.704729,-0.0489978,\[LeftSkeleton]45\
[RightSkeleton],-\
0.241191,-1.76808},\[LeftSkeleton]48\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=100;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.016 Second,{{-0.233466,0.635134,0.666035,\[LeftSkeleton]95\
[RightSkeleton],\
-1.23073,-0.520466},\[LeftSkeleton]98\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n0;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.015 Second,{{-0.252855,-0.0413172,-0.499978,\[LeftSkeleton]195\
\[RightSkeleton],0.75179,-1.44249},\[LeftSkeleton]198\[RightSkeleton],
{\
\[LeftSkeleton]1\[RightSkeleton]}}}

n=300;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.047 Second,{{1.96402,0.284784,-0.0500743,\[LeftSkeleton]295\
[RightSkeleton]\
,0.663255,-0.335565},\[LeftSkeleton]298\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=400;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.093 Second,{{0.831221,-0.288922,-1.17907,\[LeftSkeleton]395\
[RightSkeleton]\
,0.168632,-0.463928},\[LeftSkeleton]398\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=500;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.125 Second,{{-1.70821,0.0497788,-0.370148,\[LeftSkeleton]495\
\[RightSkeleton],0.36669,-0.0338988},\[LeftSkeleton]498\
[RightSkeleton],{\
\[LeftSkeleton]1\[RightSkeleton]}}}

n=600;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.188 Second,{{-0.284403,0.111908,0.527232,\[LeftSkeleton]595\
[RightSkeleton]\
,0.230411,-0.510837},\[LeftSkeleton]598\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=700;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.219 Second,{{-0.0816805,1.1005,-0.412437,\[LeftSkeleton]695\
[RightSkeleton]\
,0.196279,-2.04845},\[LeftSkeleton]698\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=800;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.344 Second,{{-2.17867,0.842315,-0.135916,\[LeftSkeleton]795\
[RightSkeleton]\
,1.88163,-1.35301},\[LeftSkeleton]798\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=900;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

{0.406 Second,{{1.58544,0.072123,-2.66405,\[LeftSkeleton]895\
[RightSkeleton],\
1.49211,-0.0905375},\[LeftSkeleton]898\[RightSkeleton],{\
[LeftSkeleton]1\
\[RightSkeleton]}}}

n=1000;
Timing[Short[A=RandomArray[NormalDistribution[],{n,n}]]]

Dimitris

{0.453 Second,{{-0.287427,-0.139428,0.221081,\[LeftSkeleton]995\
\[RightSkeleton],0.447551,-0.758528},\[LeftSkeleton]998\
[RightSkeleton],{\
\[LeftSkeleton]1\[RightSkeleton]}}}
/ amitso...@gmail.com :

Bob Hanlon

unread,
Jun 13, 2007, 7:31:11 AM6/13/07
to
$Version

5.2 for Mac OS X (June 20, 2005)

<<Statistics`NormalDistribution`;
n=500;
A=RandomArray[NormalDistribution[],{n,n}];

Dimensions[A]

{500,500}

You may have shadowed the definition of RandomArray, Start with a fresh kernel.


Bob Hanlon

Szabolcs

unread,
Jun 13, 2007, 7:44:57 AM6/13/07
to

Please provide more information.

1. Did you try quitting the kernel, than re-evaluating these expressions
(after loading the package, of course)? Does this happen every time?

2. Do you get any error messages when loading the package?

3. Are RandomArray[] and NormalDistribution[] defined? Try evaluating
?RandomArray
?NormalDistribution

If you get no error messages and the problem persists after restarting
the kernel then your Mathematica installation is most probably damaged.

Szabolcs

Jean-Marc Gulliet

unread,
Jun 13, 2007, 7:50:16 AM6/13/07
to

It looks like the package has not been loaded correctly or that the
definition is hidden for some reason. Having loaded the package,
evaluate ?NormalDistribution : you must get a help message; otherwise
something is wrong with the installed package. For instance,

In[1]:=
$Version
<< "Statistics`NormalDistribution`"
?NormalDistribution
n = 500;
Timing[A = RandomArray[NormalDistribution[], {n, n}]; ][[1]]
Dimensions[A]

Out[1]=
5.2 for Microsoft Windows (June 20, 2005)

NormalDistribution[mu, sigma] represents the normal (Gaussian)
distribution with mean mu and standard deviation sigma.

Out[5]=
0.219 Second

Out[6]=
{500,500}

Regards,
Jean-Marc

Bill Rowe

unread,
Jun 13, 2007, 8:04:21 AM6/13/07
to
On 6/12/07 at 1:24 AM, amitso...@gmail.com wrote:

>I want to create a normally distributed random matrix in
>Mathematica. I'm using the following code in Mathematica 5.2:

>------------- code ----------------------------- <<
>Statistics`NormalDistribution` n = 500; A =
>RandomArray[NormalDistribution[], {n, n}]
>------------------------------------------------

>But it is not working even though it worked when I did it earlier on
>Linux. When I enter A it just gives:

The code above should not have worked as written on any OS
running version 5.2 of Mathematica. If you look at the syntax
for the NormalDistribution function you will see it needs to be
told the mean and standard deviation. That is the correct code
would be

Statistics`NormalDistribution`
n = 500;

A = RandomArray[NormalDistribution[0,1], {n, n}]

for generating random normal deviates with mean = 0 and standard
deviation = 1
--
To reply via email subtract one hundred and four

dh

unread,
Jun 13, 2007, 8:16:34 AM6/13/07
to

Hi Amit,

if you type A and get back: RandomArray[NormalDistribution[], {500,

500}], then clearly the command has not been executed. Either

NormalDistribution or RandomArray or both are not defined. Check by

"??NormalDistribution" and "??RandomArray" to be sure these are defined.

Otherwise, I guess that "<< Statistics`NormalDistribution`" did not work.

hope this helps, Daniel

amitso...@gmail.com

unread,
Jun 18, 2007, 7:15:12 AM6/18/07
to
Thank you everyone, It started working by itself after i restarted it
again 2-3 times. This has happened earlier as well. Don't know exactly
what the problem is.

Amit

On Jun 13, 5:16 am, dh <d...@metrohm.ch> wrote:
> Hi Amit,
>
> if you type A and get back: RandomArray[NormalDistribution[], {500,
>
> 500}], then clearly the command has not been executed. Either
>
> NormalDistribution or RandomArray or both are not defined. Check by
>
> "??NormalDistribution" and "??RandomArray" to be sure these are defined.
>
> Otherwise, I guess that "<< Statistics`NormalDistribution`" did not work.
>
> hope this helps, Daniel
>

"rue dub...@news52rd.b1.woo

unread,
Jun 23, 2007, 7:09:08 AM6/23/07
to
apoline

<amitso...@gmail.com> a écrit dans le message de news:
f55pg0$jmg$1...@smc.vnet.net...

0 new messages