Want a random matrix which has a negative eigenvalues

43 views (last 30 days)
I want to generate an mxm (here I am showing a 3x3) matrix such that each element is an integer of some reasonable magnitude (let's say between 1 and 10) and who's eigenvalues are all negative. At first I did this to generate a random matix:
C = randi(10,3,3)
eig(C)
I reran this about 40 times and never got three negative eigenvalues. That seems odd. I could get every combination except all three being negative. Wouldn't the odds of that would be low. Is there something I don't understand about "randi" or worse, something I don't undertand about eigenvalues?

Accepted Answer

John D'Errico
John D'Errico on 17 Nov 2018
Edited: John D'Errico on 17 Nov 2018
Too late to really matter, but lets give this a try. First, if all of your matrix elements are positive integers, then you can never have all negative eigenvalues. (This is not difficult to prove.) So the simplest solution is to set all negative integers for your matrix. Then at least you have a chance.
As for what C'+C does, that just ensures that you have REAL eigenvalues. A symmetic matrix with real elements will have real eigenvalues.
A = -randi(10,3,3);eig(A'+A)
ans =
-28.9713024273796
-5.26725767914827
6.23856010652789
So that gives us real eigenvalues, but some negative, some positive.
Now, you might decide to just keep trying repeatedly to see if SOME matrix will eventually arise, but there is a trivial solution, whereby you can ensure the result ALWAYS on the first pass. (Hint: Gershgorin disks.)
So first create a 3x3 matrix with random off diagonal elements.
A = zeros(3);
A(logical(triu(ones(3),1))) = randi(5,3,1);
A
A =
0 2 1
0 0 4
0 0 0
A = A + A'
A =
0 2 1
2 0 4
1 4 0
It is symmetric, so it will have real eigenvalues. Some will be positive, as shown before. Now, use Gershgorin disks to ensure all eigenvalues wiill be negative and real.
Since ALL elements of A are no larger than 5, then no row sum can possibly be greater than 10. But we can do even better, by using the existing row sums of A, .
A = A - diag(sum(A,2) + randi(5,3,1))
A =
-6 2 1
2 -9 4
1 4 -9
eig(A)
ans =
-13.0766925998031
-7.62276318027942
-3.30054421991745
You can even prove that the matrix as created will always have negative eigenvalues, with no need to try a second time.
  2 Comments
Jon Games
Jon Games on 17 Nov 2018
Edited: Jon Games on 17 Nov 2018
I unaccepted the answer to this questions and accepted yours. I tried the accepted answer and it didn't work it just gave me real eigenvalues instead of negative eigenvalues. Although I didn't actually ask for real eigenvalues I'm glad your answer stated how to get real eigenvalues. What I want is all negative eigenvalues and you answer provided that. It is even better that they are all real AND negative.

Sign in to comment.

More Answers (2)

David Goodmanson
David Goodmanson on 17 Nov 2018
Edited: David Goodmanson on 17 Nov 2018
Hi Jon,
The sum of the eigenvalues of a matrix equals the trace of the matrix. If all eigenvalues are negative their sum would be negative, but with rand(10,n,n) supplying only positive elements, the trace is positive. So you can't have all negative eigenvalues.
  1 Comment
Jon Games
Jon Games on 17 Nov 2018
@David: Thank you for explaining why. Evidently I didn't know something about the nature of eigenvalues. That ignorance was the source of my problem. Now I know why my code would have never worked.

Sign in to comment.


KSSV
KSSV on 17 Nov 2018
C = randi(10,3,3) ;
C = C'+C
eig(C)
  2 Comments
Jon Games
Jon Games on 17 Nov 2018
I wish you would have explained why C' + C would work. You answered first and that solved my problem I just wish you would have explained why this works. Thank you for your answer.
Jon Games
Jon Games on 17 Nov 2018
Edited: Jon Games on 17 Nov 2018
This doesn't actually work. What I wanted was all negative eigenvalues. Your solution only gaurantees that I will get real eigenvalues.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!