Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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@RandomReal[{-1,1},{r,r}](*orthonormal eigenvectors*)
A=Transpose[v].eig.v
Eigenvalues[A]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.