# Generate Random Symmetric positive definite matrix

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

• Define "random." – David G. Stork Dec 14 '18 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) – revanth roy Dec 14 '18 at 5:29
• @revanthroy That does not define "random". You have to specify a probability distribution. – Henrik Schumacher Dec 14 '18 at 7:05

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*)

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. – Henrik Schumacher Dec 14 '18 at 7:09