'How to generate random matrices for given eigenvalues in matlab?
Is there an easy way to generate random matrices, all with eigenvalues that I'll choose?
Solution 1:[1]
Given a diagonal matrix containing all the eigenvalues you want, you can use a similarity transformation of a random (but invertible) matrix to do what you want:
>> lambda = [-1 -2 -3] % These are the eigenvalues you want
lambda =
-1 -2 -3
>> A = diag(lambda)
A =
-1 0 0
0 -2 0
0 0 -3
>> eig(A)
ans =
-3
-2
-1
>> S = rand(size(A)); % Random matrix of compatible size with A.
>> B = inv(S)*A*S % Random matrix with desired eigenvalues, using similarity transformation
B =
-2.7203 -0.5378 -0.9465
2.0427 -0.1766 1.2659
-2.0817 -1.8974 -3.1031
>> eig(B)
ans =
-3.0000
-1.0000
-2.0000
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
