3
$\begingroup$

I want to generate 3 random symmetric matrices, each of dimension 3 whose elements are normally distributed. It could be done simply as

A = RandomVariate[NormalDistribution[0, 1], {3, 3}]
B = RandomVariate[NormalDistribution[0, 1], {3, 3}]
C = RandomVariate[NormalDistribution[0, 1], {3, 3}]
R1 =(A + Transpose[A])/2
R2 =(B + Transpose[B])/2
R3 =(C + Transpose[C])/2

I am looking for other ways in which the same problem can be done for the case where number of matrices is large.

$\endgroup$
  • $\begingroup$ If you have a recent version of Mathematica, there are a lot of built-in distributions for random matrices. See reference.wolfram.com/language/guide/MatrixDistributions.html for more. $\endgroup$ – Pillsy Apr 28 '17 at 19:46
  • $\begingroup$ I can't see any problem with what you are doing - do you want a simple function that generates a random matrix? $\endgroup$ – mikado Apr 28 '17 at 19:50
  • $\begingroup$ @mikado I want to generate 1000 random symmetric matrices for which using this code isn't a good idea. I am looking for better algorithm or a function to do so. $\endgroup$ – NerdySnail Apr 28 '17 at 19:56
  • $\begingroup$ @NerdySnail Do you want just a few matrices (so you can hand pick the names) or a whole slew of them? $\endgroup$ – Igor Rivin Apr 29 '17 at 15:43
  • $\begingroup$ Let's say we have 100 of them. Handpicking would be absurd. $\endgroup$ – NerdySnail Apr 29 '17 at 16:26
3
$\begingroup$

Firstly, your method does not work. The diagonal elements are $\mathcal{N}(0, 1),$ the off-diagonal elements are $\mathcal{N}(0, \frac{1}{\sqrt{2}}).$ Secondly, GaussianOrthogonalMatrixDistribution[\[Sigma],n] does work (in your case, $\sigma = 1, n=3.$

EDIT as pointed out by Mikey, the mathematica command does the wrong thing. However, this does:

randomSymMat = 
  Module[{mat = RandomVariate[#, {#2, #2}], upper, diag}, 
    upper = UpperTriangularize[mat, 1]; 
    diag = DiagonalMatrix[Diagonal@mat]; 
    diag + upper + Transpose[upper]] &;

so

randomSymMat[NormalDistribution[0, 1], #]& /@ Array[3&, 1000]

Will do what you need.

$\endgroup$
  • $\begingroup$ hmmm...reading the docs, GaussianOrthogonalMatrixDistribution[] is a distribution of a symmetric matrix (x+x^T)/2, where x is a square matrix with independent identically distributed matrix elements that follow NormalDistribution[0,[Sigma]]. Sure sounds like x is distributed same as A in his question, no? $\endgroup$ – MikeY Apr 28 '17 at 20:19
  • $\begingroup$ @Igor,Indeed.As Pillsy already mentions,I should have used MatrixDistributions. However doing that too,doesn't lead us closer to the actual problem of generating a thousand of such matrices in a go. $\endgroup$ – NerdySnail Apr 28 '17 at 20:21
  • $\begingroup$ @MikeY That is NOT the Gaussian Orthogonal Matrix Distribution, so either the name is wrong or the docs are wrong. $\endgroup$ – Igor Rivin Apr 28 '17 at 20:22
  • $\begingroup$ @MikeY The docs are NOT wrong. This is really messed up. $\endgroup$ – Igor Rivin Apr 28 '17 at 20:25
  • $\begingroup$ @IgorRivin You can report the problem at the Give Feedback link here: reference.wolfram.com/language/ref/… $\endgroup$ – Alan Apr 28 '17 at 21:17
2
$\begingroup$

OK, here's my shot at it.

makeMat[eps_, n_] := (res = RandomVariate[NormalDistribution[0, eps], {n, n}];
                     UpperTriangularize[res] + Transpose@UpperTriangularize[res, 1])

makeMat[1,3]

$$ \left( \begin{array}{ccc} 0.733676 & 0.0102509 & -0.35534 \\ 0.0102509 & -0.462317 & -0.132434 \\ -0.35534 & -0.132434 & 0.89037 \\ \end{array} \right) $$

$\endgroup$

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.