# Thread: Problem with Mathematica Statistics'NormalDistribution'

1. ## Problem with Mathematica Statistics'NormalDistribution'

Hey there,

I'm getting a very odd error, and I would be grateful for any help solving it.

I have a notebook with the following:

(* Amy's program to generate random orthogonal matrices (RUM) and sort their \
eigenvalues (EigenRUM)*)
<< LinearAlgebraMatrixManipulation
<< StatisticsNormalDistribution
RUM[NxN_] := (
f[x_, y_] := Random[NormalDistribution[0, 1]];
RM1 = Array[f, {NxN, NxN}];
RM2 = QRDecomposition[RM1];
R1 = Flatten[Drop[RM2, 1], 1];
f2[x_] := R1[[x, x]]/Abs [R1[[x, x]]];
R2 = Array[f2, NxN];
R3 = DiagonalMatrix[R2];
Q1 = Flatten[Take[RM2, 1], 1];
Q2 = Conjugate[Transpose[Q1]];
Transpose[Q2].Q2;
RM = Q2.R3);

I wrote this over two years ago, and several members of my department and I have been using it happily since - until today, when it has suddenly started throwing up errors - specifically:

NormalDistribution::shdw: Symbol NormalDistribution appears in multiple \
contexts {StatisticsNormalDistribution, Global}; definitions in context \
StatisticsNormalDistribution may shadow or be shadowed by other definitions.

The notebook has not been altered since it was last working, so I am very confused as to why it now has errors.

I also get the error

Random::randt: Type specification NormalDistribution[0, 1] in \
Random[NormalDistribution[0, 1]] should be Real, Integer, or Complex.

on running

Random[NormalDistribution[0, 1]]
by itself. I've read through the help page on NormalDistribution, but even trying to input the examples from there throws up errors.

Anyone who can shed any light on this will receive a lot of gratitude, as my PhD is kinda at a standstill unless I can generate random orthogonal matrices!

2. Originally Posted by AmyMarieMason
Hey there,

I'm getting a very odd error, and I would be grateful for any help solving it.

I have a notebook with the following:
(* Amy's program to generate random orthogonal matrices (RUM) and sort their \
eigenvalues (EigenRUM)*)
<< LinearAlgebraMatrixManipulation
<< StatisticsNormalDistribution
RUM[NxN_] := (
f[x_, y_] := Random[NormalDistribution[0, 1]];
RM1 = Array[f, {NxN, NxN}];
RM2 = QRDecomposition[RM1];
R1 = Flatten[Drop[RM2, 1], 1];
f2[x_] := R1[[x, x]]/Abs [R1[[x, x]]];
R2 = Array[f2, NxN];
R3 = DiagonalMatrix[R2];
Q1 = Flatten[Take[RM2, 1], 1];
Q2 = Conjugate[Transpose[Q1]];
Transpose[Q2].Q2;
RM = Q2.R3);
I wrote this over two years ago, and several members of my department and I have been using it happily since - until today, when it has suddenly started throwing up errors - specifically:

NormalDistribution::shdw: Symbol NormalDistribution appears in multiple \
contexts {StatisticsNormalDistribution, Global}; definitions in context \
StatisticsNormalDistribution may shadow or be shadowed by other definitions.

The notebook has not been altered since it was last working, so I am very confused as to why it now has errors.

I also get the error

Random::randt: Type specification NormalDistribution[0, 1] in \
Random[NormalDistribution[0, 1]] should be Real, Integer, or Complex.

on running
Random[NormalDistribution[0, 1]]
by itself. I've read through the help page on NormalDistribution, but even trying to input the examples from there throws up errors.

Anyone who can shed any light on this will receive a lot of gratitude, as my PhD is kinda at a standstill unless I can generate random orthogonal matrices!
Has the version of M. been updated?

CB

3. No, Mathematica hasn't been updated since the Autumn.

4. First thing just restart Mathematica and see if the problem is resolved then:

NormalDistribution has been added to the built-in functions in ver 6 and 7. Did you guys upgrade? If so, then just omit <<StatisticsNormalDistribution from your code. You can verify if it's a built-in function with:

Names["SystemNormalDistribution"]

which returns:

{"NormalDistribution"}

on my ver 7 meaning it's now part of the "System" context so if I were to enter:

<<StatisticsNormalDistribution

I would now have two variable names with the same name, one in system context and the other in "Statistics" context and Mathematica would use the first one on the context search path unless I explicitly specified the context name and would also give me an error like you got.

Also, don't use upper case variable names since all the built-in function names begin with upper case names and this might cause conflict.

5. Originally Posted by shawsend
First thing just restart Mathematica and see if the problem is resolved then:
Restarting definately does not solve the problem. So far we've tried this on two computers, connecting to three different servers on the university farm (We don't have personal copies of Mathematica, but the department has three different machines that run it we can access) - all give the same errors.

Originally Posted by shawsend
NormalDistribution has been added to the built-in functions in ver 6 and 7. Did you guys upgrade? .
The sys admin says there have been no upgrades since the Autumn, and the problem only appeared on Friday (ie. running without errors Friday morning, errors from early Friday afternoon)

Originally Posted by shawsend
If so, then just omit <<StatisticsNormalDistribution from your code. You can verify if it's a built-in function with:

Names["SystemNormalDistribution"]

which returns:

{"NormalDistribution"}

on my ver 7
Typing
Names["SystemNormalDistribution"]
Returns
{}
Restarting Mathematica, and just entering

Random[NormalDistribution[0,1]
gets the error

Random::randt: Type specification NormalDistribution[0, 1] in \
Random[NormalDistribution[0, 1]] should be Real, Integer, or Complex.

So I don't think it can be that NormalDistribution is part of the "System" context.

But thanks for the help!

6. What version do you have?

Now, startup Mathematica and try this:

Enter:

?NormalDistribution

You'll get a definition if it's a built-in function or empty list if it's not.

If it's not yet defined, then enter:

<<Statistics'NormalDistribution
?NormalDistribution

That should load the package "Statistics with the function NormalDistribution and the ?NormalDistribution should then give you a description of the function.

7. Version 5.0.1.0

Typing

?NormalDistribution gets:

Typing ...

Okay, now that is super duper weird. It just started working again.

I'm not sure what just happened, but it seems to have fixed itself - no error messages, producing random numbers, running the whole notebook happily.

Sometimes, I really hate computers...

Thank you very much for your time