0
$\begingroup$

I am just trying to create many number of random 3x3 matrices in the array (-100,100) for a statistical research and I am stuck to create symmetric many number of matrices. And also those matrices should be defined by letters, because after generation, all of those matrices place in an equation.

h[n_] := Module[{m}, m = RandomReal[{-100, 100}, {3, 3}];
m SparseArray[{i_, j_} /; i >= j -> 1, {3, 3}] + 
Transpose[m SparseArray[{i_, j_} /; i > j -> 1, {3, 3}]] // Normal]
h[3] // MatrixForm 
For[n = 0, n < 1000, n++, Print[h[n] // MatrixForm]]

with these code I can create 3x3 symmetric 1000 matrices, but how can I define these matrices as stable. I mean for example, for this code when I print h[7], everytime it gives another random matrix. How can I store those 1000 matrices for variables of h (h[n]) (I want stable matrices When I print any value of h[n]) ?

$\endgroup$
  • 2
    $\begingroup$ add SeedRandom[1]; before m = RandomReal[...]; $\endgroup$ – kglr Dec 25 '17 at 12:37
  • $\begingroup$ When I do that, every matrices give same solution for example h[1] and h[2] give the same matrix :/ $\endgroup$ – kejinatsu Dec 25 '17 at 13:02
1
$\begingroup$

This creates 1000 symmetric random 3-by-3 matrices at once.

m = RandomReal[{-100, 100}, {1000, 3, 3}];
Do[m[[All, i, j]] = m[[All, j, i]], {i, 1, 3}, {j, i + 1, 3}];

You can reference the n-th matrix with m[[n]]. Note the double brackets as m is a three dimensional array. If you insist on single brackets then define

h[n_]:=m[[n]]
$\endgroup$
  • $\begingroup$ Thank you! Thats exactly what I want, I really appriciate that :) $\endgroup$ – kejinatsu Dec 25 '17 at 13:08
  • $\begingroup$ You're welcome! $\endgroup$ – Henrik Schumacher Dec 25 '17 at 13:18
0
$\begingroup$
letter = Alphabet[]

h[n_] := Module[{m}, SeedRandom[n]; m = RandomChoice[letter, {3, 3}];
                 m SparseArray[{i_, j_} /; i >= j -> 1, {3, 3}] + 
                 Transpose[m SparseArray[{i_, j_} /; i > j -> 1, {3, 3}]] // Normal]

h[3] // MatrixForm

For[n = 0, n < 1000, n++, Print[h[n] // MatrixForm]]

{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

$\left( \begin{array}{ccc} \text{p} & \text{i} & \text{v} \\ \text{i} & \text{b} & \text{o} \\ \text{v} & \text{o} & \text{s} \\ \end{array} \right)$

... 1000 matrices ...

If you want different set use a different seed, for example, SeedRandom[n+3] or SeedRandom[n+17].

$\endgroup$
  • $\begingroup$ You get me wrong I think I just want to create matrices for each value of matrices should be array of -100,100 but I Just define those matrices. with letter for example h[1] or h[2] or so on, I created this matrices but I cant store it with variables $\endgroup$ – kejinatsu Dec 25 '17 at 12:57

Your Answer

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

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