# Generate random symmetric matrix with largest eigenvalue approximately 1

My goal is to generate a positive (entry-wise) matrix $$P\in \mathbb{R}_{>0}^{N\times m}$$ and then to set $$S=PP^T$$ such that the largest eigenvalue of $$S$$ is $$\approx 1$$ (or equal). Note that if $$y$$ is a row vector then $$ySy^T=(yP)(yP)^T=\|yP\|^2 \geq 0$$ so $$S$$ is positive semidefinite, and since $$S$$ is also symmetric, all the eigenvalues are thus real and positive.

I am not quick with linear algebra, so I first tried looking into factorizations of a symmetric PSD matrix. For example since $$S$$ is symmetric and real we can write $$S=Q\Lambda Q^T$$ where $$QQ^T=I$$ is an orthogonal matrix whose columns are the eigenvectors of $$S$$ and $$\Lambda$$ is a diagonal matrix with the eigenvalues on the diagonal. Since these are real and positive we can write $$S=(Q \Lambda^{1/2})(Q \Lambda)^T$$ so I tried to start with randomly generating $$P=Q\Lambda$$ by specifying the eigenvalues to start with $$1,\lambda_2,\dotsc$$ in decreasing order randomly and $$Q$$ a random orthogonal matrix. But then $$P$$ is not necessarily positive, and so neither is $$S$$ which I need. Any pointers would be greatly appreciated. I repeat the question below for succinctness.

My Question Is it possible to generate a random symmetric matrix of the form $$S=PP^T$$ where $$P$$ is positive entrywise and the largest eigenvalue of $$S$$ is $$1$$?

• What are the required dimensions of $P$? May 25, 2022 at 1:16
• @JimmyK4542 $P$ does not necessarily need to be square, but $P\in \mathbb{R}_{>0}^{N\times m}$ where $m\leq N$, and if if can be done with $m>N$ I’d be interested in that too. I’ll add this to the main body of the question too. May 25, 2022 at 1:24

One way to generate a random symmetric matrix of the form $$S=PP^T$$ where $$P$$ is positive entrywise and the largest eigenvalue of $$S$$ is $$1$$ is to let $$R$$ be an $$n \times m$$ matrix whose entries are i.i.d. from any distribution whose support is contained in $$(0,\infty)$$, and then let $$P = \tfrac{1}{\sigma_1(R)}R$$, where $$\sigma_1(R)$$ is the largest singular value of $$R$$. The entries of $$R$$ are all positive, and it's largest singular value is positive, so the entries of $$P$$ are all positive. Furthermore, the largest eigenvalue of $$RR^T$$ is $$\sigma_1(R)^2$$, so the largest eigenvalue of $$S = PP^T = \tfrac{1}{\sigma_1(R)^2}RR^T$$ is $$1$$.