Could anybody tell me how to generate random symmetric positive definite matrices using MATLAB?
How to generate random symmetric positive definite matrices using MATLAB?
84.1k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 3 best solutions below
On
The following is not computationally efficient but very simple. You could fill a matrix $\bf A$ with random values, computed for some desired distribution. Then you define a new matrix $\bf B = \bf{A} + \bf{A}^T$ in order to get a symmetric matrix. Then you use matlab to compute the eigenvalues of this matrix. If $\mathbf{B}$ doesn't happen to be positive definite, construct a new matrix matrix by
$$\bf{C} = \bf{B} + (|\lambda_{min}| + \delta)\bf{I}$$
where $|\lambda_{min}|$ is the absolute value of the smallest eigenvalue of $\bf{B}$ and $\delta$ is some small positive constant which defines the smallest eigenvalue of the your final matrix $\bf{C}$.
On
A usual way in Bayesian statistics is to sample from a probability measure on real symmetric positive-definite matrices such as Wishart (or Inverse-Wishart).
I don't use Matlab but a quick check on Google gives this command (available in the Statistics toolbox):
W = wishrnd(Sigma,df)
where Sigma is some user-fixed positive definite matrix such as the identity and df are degrees of freedom.
The algorithm I described in the comments is elaborated below. I will use $\tt{MATLAB}$ notation.
Several changes are able to be used in the case of a sparse matrix.
In fact, if the desired eigenvalues of the random matrix are known and stored in the vector
rc, then the commandwill construct the desired matrix. (Source: MATLAB sprandsym website)