Want a random matrix which has a negative eigenvalues

9 次查看(过去 30 天)
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?

采纳的回答

John D'Errico
John D'Errico 2018-11-17
编辑:John D'Errico 2018-11-17
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 个评论
Jon Games
Jon Games 2018-11-17
编辑:Jon Games 2018-11-17
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.

请先登录,再进行评论。

更多回答(2 个)

David Goodmanson
David Goodmanson 2018-11-17
编辑:David Goodmanson 2018-11-17
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 个评论
Jon Games
Jon Games 2018-11-17
@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.

请先登录,再进行评论。


KSSV
KSSV 2018-11-17
C = randi(10,3,3) ;
C = C'+C
eig(C)
  2 个评论
Jon Games
Jon Games 2018-11-17
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 2018-11-17
编辑:Jon Games 2018-11-17
This doesn't actually work. What I wanted was all negative eigenvalues. Your solution only gaurantees that I will get real eigenvalues.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by