How can I generate random invertible symmetric positive semidefinite square matrix using MATLAB?
36 views (last 30 days)
Show older comments
Dinoma Degefa
on 4 Sep 2018
Answered: Walter Roberson
on 4 Sep 2018
matrixSize = 10
A = random.rand(matrixSize,matrixSize)
B = numpy.dot(A,A.transpose())
I am not sure, this generates random positive semi-define matrix B. But I want to generate random invertible symmetric positive semidefinite square matrix. Thank for your help.
Accepted Answer
Walter Roberson
on 4 Sep 2018
matrixSize = 10;
while true
A = rand(matrixSize, MatrixSize);
if rank(A) == matrixSize; break; end %will be true nearly all the time
end
B = A' * A;
According to https://en.wikipedia.org/wiki/Positive-definite_matrix, for any square matrix A, A' * A is positive semi-definite, and rank(A' * A) is equal to rank(A) . Matrices are invertible if they have full rank. So all we have to do is generate an initial random matrix with full rank and we can then easily find a positive semi-definite matrix derived from it. Nearly all random matrices are full rank, so the loop I show will almost always only iterate once and is very very unlikely to need more than a very small number of iterations.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!