2
$\begingroup$

does anyone know any matlab algorithm that can help me generate a random matrix with REAL EIGEN values? Thanks.

$\endgroup$
  • 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 Lipinski Sep 27 '15 at 1:26
6
$\begingroup$

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)
$\endgroup$
  • 1
    $\begingroup$ Wonderful. I think my problem has been solved by your answer. You guys are too awesome. Thanks $\endgroup$ – user1144656 Sep 27 '15 at 1:32
  • $\begingroup$ Which is the answer I should have been able to come up with. Nice. $\endgroup$ – Bill Barth Sep 27 '15 at 2:57
  • $\begingroup$ @user1144656 If this answer solved your problem, you should accept it! $\endgroup$ – Christian Clason Oct 3 '15 at 21:25
1
$\begingroup$

If you want to specify the eigenvalues, then you can just put them on the diagonal of an otherwise empty matrix.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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