How to generate a large PSD matrix $A \in \mathbb{R}^{n \times n}$, where $\mathcal{O}(n) \sim 10^3$

262 Views Asked by At

I would like to generate a large PSD matrix, i.e., $A \in \mathbb{R}^{n \times n}$, where $\mathcal{O}(n) \sim 10^3$. The entries of the matrix should be randomly generated using a standard function in Python, or Mathematica or any other language.

The current method I am using is as follows:

  1. First, generate a matrix $P$ with random real and positive values. (I set them to integers by rounding).

  2. Set $A = PP^T$

The matrix I have gotten is symmetric, but usually positive definite (the eigenvalues tends to be non-zero, say, 0.004).

  • Is there a way to update the positive definite matrix into a positive semidefinite matrix?

    If not, is there a better method for generating large, positive semidefinite matrix?