5
$\begingroup$

I need to generate an nxn matrix with random entries, but I also need all of the eigenvalues to be negative (real or complex doesn't matter). I have:

r = 4; (* matrix dimension *) dom = {1, 10}; (* domain of random numbers *) eig = DiagonalMatrix[-RandomInteger[dom, r]] (* eigenvalues in diagonal matrix *) v = RandomVariate[NormalDistribution[], {r, r}] (* normalized eigenvectors? *) A = v.eig.v Eigenvalues[A] 

It seems like this should work, as the eigenvalues are all negative, but sometimes I still get positive eigenvalues. What am I doing wrong here?

Thanks.

$\endgroup$

2 Answers 2

12
$\begingroup$

RandomVariate[NormalDistribution[], {r, r}] does not give you normalized eigenvectors. To obtain an orthonormal basis, you can first generate a random matrix, and then apply Orthogonalize to it. Following is the correct code.

r=4;(*matrix dimension*) dom={1,10};(*domain of random numbers*) eig=DiagonalMatrix[-RandomInteger[dom,r]] (*eigenvalues in diagonal matrix*) v=Orthogonalize@RandomVariate[NormalDistribution[], {r, r}](*orthonormal eigenvectors*) A=Transpose[v].eig.v Eigenvalues[A] 
$\endgroup$
3
  • 1
    $\begingroup$ For uniformly distributed orthogonal matrices, use v = Orthogonalize[RandomVariate[NormalDistribution[], {r, r}]] instead. $\endgroup$ Commented Nov 19, 2019 at 10:48
  • $\begingroup$ @J.M. thanks for pointing out, I have updated the answer $\endgroup$ Commented Nov 20, 2019 at 8:54
  • $\begingroup$ Random orthogonal matrices can also be produced with RandomVariate[CircularRealMatrixDistribution[r]]. However, J.M.'s approach seems to be faster. $\endgroup$ Commented Nov 20, 2019 at 11:02
7
$\begingroup$

Just make a random matrix with all positive eigenvalues and then add a minus sign:

r = 4; M = -#.ConjugateTranspose[#]&[RandomVariate[NormalDistribution[], {r,r,2}].{1,I}] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.