How can I generate random invertible symmetric positive semidefinite square matrix using MATLAB?

조회 수: 34 (최근 30일)
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.

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 4일
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by