does anyone know any matlab algorithm that can help me generate a random matrix with REAL EIGEN values? Thanks.
-
1$\begingroup$ What is your definitions of "random matrix"? If you want some distribution over all matrices with real eigenvalues this is hard. If you want a distribution over all possible real eigenvalues you could do something as simple as a diagonal matrix with random entries on the diagonal. $\endgroup$– Doug LipinskiSep 27, 2015 at 1:26
2 Answers
You don't mention what kind of distribution you want for the entries of the random matrix, so the simplest recipe that I can think of is to first create a random $n \times n$ matrix $\mathtt{A}$ and to then obtain $\mathtt{B} = \frac{1}{2} ( \mathtt{A} + \mathtt{A}^{\mathtt{T}} )$. That gives you a symmetric matrix $\mathtt{B}$ with random entries. Since symmetric matrices have real eigenvalues, the matrix $\mathtt{B}$ will satisfy your requirement.
Matlab code:
A = rand(n)
B = 0.5 * (A + transpose(A))
Here's another approach, building on Bill Barth's answer. First, create a random diagonal matrix $\mathtt{D}$, then obtain a random orthogonal matrix $\mathtt{Q}$ and, finally, compute the similarity transformation $\mathtt{B} = \mathtt{Q} \, \mathtt{D} \, \mathtt{Q}^{\mathtt{T}}$. The matrix $\mathtt{B}$ will have the same eigenvalues as $\mathtt{D}$ but will not be diagonal in general. A simple way to come up with a random orthogonal matrix $\mathtt{Q}$ is to compute the QR decomposition of a random matrix.
Matlab code:
D = diag(rand(n, 1))
[Q ~] = qr(rand(n))
B = Q * D * transpose(Q)
-
1$\begingroup$ Wonderful. I think my problem has been solved by your answer. You guys are too awesome. Thanks $\endgroup$ Sep 27, 2015 at 1:32
-
$\begingroup$ Which is the answer I should have been able to come up with. Nice. $\endgroup$ Sep 27, 2015 at 2:57
-
$\begingroup$ @user1144656 If this answer solved your problem, you should accept it! $\endgroup$ Oct 3, 2015 at 21:25
If you want to specify the eigenvalues, then you can just put them on the diagonal of an otherwise empty matrix.