0
$\begingroup$

I am a novice in Mathematica and coding, in general. I have doubts in understanding a code in which nearest neighboring distance between eigen values of random matrices is evaluated.

    (* No. of members in ensemble=ns; Matrix dimension=n*)
    ns = 1000;
    n = 20
    Ev = {}; Sp = {}; Xd = {}; Sxd = {};
    Monitor[For[i = 1, i < ns + 1, i++, {
    A = RandomVariate[NormalDistribution[], {n, n}];
    H = (A + Transpose[A])/Sqrt[2 n];
   \[CapitalLambda] = Sort[Eigenvalues[H]];
    S = Table[\[CapitalLambda][[j + 1]] - \[CapitalLambda][[j]], {j, 1,
    n - 1}];
    Ev = Join[Ev, \[CapitalLambda]];
    Sp = Join[Sp, S];

     X = Table[
     n/(2 \[Pi])
     NIntegrate[Sqrt[4 - x^2], {x, -2,  \[CapitalLambda][[j]]}], {j, 
     1, n}];
     Sx = Table[X[[j + 1]] - X[[j]], {j, 1, n - 1}];
     Xd = Join[Xd, X];
     Sxd = Join[Sxd, Sx];
     }
     ], i]
  1. Can the following be explained? Ev = Join[Ev, Λ]; Sp = Join[Sp, S]; I know Join is meant to concatenate two lists but here the variable on lhs Ev is also on the rhs in the argument of Join. So What does these two assignments mean and what purpose do they serve here?
  2. If I need to plot only a hisrogram of Eigen values Ev, Would Sorting the list of eigen values make any difference? I mean one can still have the histogram without having to sort them. Isn't it?

  3. I wanted to do this whole task by functional programming. If anyone can give hint on how to start and proceed for that.

Thank you.

$\endgroup$
  • $\begingroup$ The fact that Ev is on the rhs is totally fine. The current value of Ev just gets copied in, joined to \[CapitalLambda] and that gets assigned to Ev. I don't have the time right now to write you a functional implementation, but a quick glance at your code suggests you'll want to use want Fold. Also sorting the eigenvalues won't matter at all. Histogram will do that automatically. $\endgroup$ – b3m2a1 Apr 2 '17 at 20:15
  • $\begingroup$ Yeah, I just figured out why Ev is on rhs after posting the question.Thanks for help. $\endgroup$ – NerdySnail Apr 2 '17 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.