Generate Random Symmetric positive definite matrix

Is there any way to create a random symmetric positive definite matrix ?

• Define "random." Dec 14, 2018 at 4:59
• @David G. Stork sir, thanks for the reply,actually i want to create a positive definite matrix randomly in the range from (-1 ,1) Dec 14, 2018 at 5:29
• @revanthroy That does not define "random". You have to specify a probability distribution. Dec 14, 2018 at 7:05

dim = 10;

RandomVariate[GaussianOrthogonalMatrixDistribution[dim]]


or

With[{U = RandomVariate[CircularRealMatrixDistribution[dim]]},
U.(RandomReal[{-1, 1}, dim] U\[Transpose])
]

• Since OP did not specify a precise probability distribution, this question cannot be answered precisely. Dec 14, 2018 at 7:09
• Looks like the first option does not produce an SPD matrix. Try SeedRandom[0]; dim = 2; m = RandomVariate[GaussianOrthogonalMatrixDistribution[dim]]; Eigenvalues[m]with output {-1.21836, -0.0868584}. Both eigenvalues are negative.
– A.G.
May 20, 2021 at 15:17

Translation to Mathematica:

n    = 5; (*size of matrix, change as needed*)
q    = Table[RandomReal[{-1, 1}], {n}, {n}];
mat  = Transpose[q].q;
PositiveDefiniteMatrixQ[mat]
(*true*)


The matrix symmetric positive definite matrix A can be written as , A = Q'DQ , where Q is a random matrix and D is a diagonal matrix with positive diagonal elements. The elements of Q and D can be randomly chosen to make a random A.

Here is the translation of the code to Mathematica

n         = 5; (*size of matrix. Change as needed *)
q         = Table[RandomReal[{-1, 1}], {n}, {n}];
eigenMean = 2; (*see link above *)

mat = Transpose[q].DiagonalMatrix[eigenMean + Table[RandomReal[{-1, 1}], {n}]].q;

PositiveDefiniteMatrixQ[mat]
(*true*)