0
$\begingroup$

I have the following code to generate random data (these are the eigenvalues of a non-central Wishart matrix, and I am interested in their distribution).

m = 2;
n = 3;
nonce = {{1, 0}, {0, 0}, {0, 0}};
count = 0;
    Do[q = RandomVariate[NormalDistribution[], {n, m}] + nonce;
    a = Dot[Transpose[q], q];
    l1[count] = Min[Eigenvalues[a]];
    count++, {3}]

Now, this creates some sort of object l2 with count number of elements. When I want to use the EmpiricalDistribution function on it, however, I obtain the following error:

EmpiricalDistribution::rectn: Rectangular array of real numbers is expected at position 1 in EmpiricalDistribution[l1]. >>

I have tried the Flatten function on l1 but that seems to not do the trick. Can anyone help me how to get the EmpiricalDistribution function for this?

The point of this exercise is to compare this simulated result to my theoretical calculations.

Thank you so much!

Hirek

$\endgroup$

1 Answer 1

1
$\begingroup$

I figured it out and I believe this is one of the biggest pitfalls for newbies. Rather than filling a preallocated vector, MATLAB style, one ought to use the function table instead, which executes the expression k number of times.

Hence, the following code does it:

m = 2;
n = 3;
nonce = {{1, 0}, {0, 0}, {0, 0}};
data = Table[q = RandomVariate[NormalDistribution[], {n, m}] + nonce; 
  a = Dot[Transpose[q], q]; l1 = Min[Eigenvalues[a]]; l1, {10}]

What I was not sure about was how to go about intermediate steps but simply suppressing output of intermediate steps works.

Another detail that was important is that the q stays the same in each iteration, since otherwise we would not get a Wishart distribution.

Cheers!

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.