0

How can we randomly create a real squared matrix A and all of its eigenvalues are complex number λ=a+bi in Matlab?

Patrick48
  • 1
  • 1

3 Answers3

0

I'll first take a random n X 2 data matrix, A, with n > 2. We want the columns of A to have similar variance and there to be some correlation between the columns. You can achieve this using the choleski decomposition of a 2x2 covariance matrix. Then we'll take the sample covariance matrix of A, lets call this B. If we change B(1,2) = -B(1,2) then B will have complex eigen values with high probability.

The reason for this is a covariance matrix is of the form [a,b;b,c] and the fundamental equation for the matrix is (a-lam)*(c-lam) - b^2. In order for this to have complex eigen values we need 4*a*c -4*b^2 > (a+c)^2. Which can be written as -4*b^2 > (a-c)^2. This can't happen, unless we change B(1,2) = -B(1,2) then the requirement becomes 4*b^2 > (a-c)^2. So since a and c are the variances of the columns of A, if they have similar variance (a-c)^2 will be close to zero. and if the columns of A have decent correlation then 4b^2 will be far from zero and positive. Therefore you get complex eigen values.

This shouldn't be too hard to extend to general nxn matrices.

dusty_keyboard
  • 136
  • 1
  • 5
  • 1
    @Luan you should note that the eigen values of any NxN matrix are the roots of an N'th order polynomial. As such, if N is odd there will always be at least one real root to the polynomial. So it is not possible to generate a matrix without atleast 1 real eigen value if each element in the matrix is real and N is odd. – dusty_keyboard Aug 20 '14 at 08:24
0

I have tried to extend to general nxn matrices. One issue is that if n is odd, Matlab always generates at least one real eigenvalues e.g : n = 3 random_matrix = cov(rand(3));

for i = 1: length(random_matrix)
    for j = 1: length(random_matrix)
        if j > i
           random_matrix(i,j) = - random_matrix(i,j);
        end
    end    
end 

random_matrix =

0.1390   -0.1389    0.0578
0.1389    0.1661    0.0257 

-0.0578 -0.0257 0.0614

eig(random_matrix) =

0.1457 + 0.1483i

0.1457 - 0.1483i

0.0752 + 0.0000i

is there any better way to randomly generate a real stable matrix which only has imaginary part of eigenvalues ?

Patrick48
  • 1
  • 1
0

Note the eigenvalues are conjugates of one another and so are the eigenvectors. Note that the resulting matrix A has all real entries.

>> syms a b c d e real    

>> D=diag([a+b*i,a-b*i])


D =

[ a + b*i,       0]
[       0, a - b*i]

>> V=[c, c;d+e*i, d-e*i]

V =

[       c,       c]
[ d + e*i, d - e*i]

>> A=simplify(V*D*inv(V))

A =

[          (a*e - b*d)/e,       (b*c)/e]
[ -(b*(d^2 + e^2))/(c*e), (a*e + b*d)/e]

Thus, suppose you want a real matrix with eigenvalues 1+i and 1-i and eigenvectors (1,1+i) and (1,1-i).

>> D=sym(diag([1+i,1-i]))

D =

[ 1 + i,     0]
[     0, 1 - i]

>> V=sym([1,1;1+i,1-i])

V =

[     1,     1]
[ 1 + i, 1 - i]

>> A=simplify(V*D*inv(V))

A =

[  0, 1]
[ -2, 2]

And we can check our answer.

>> [v,d]=eig(A)

v =

[ 1/2 + i/2, 1/2 - i/2]
[         1,         1]


d =

[ 1 - i,     0]
[     0, 1 + i]

At first, we think it didn't return the same eigenvectors that we entered. However, any multiple of an eigenvector is still an eigenvector, and look what happens when we multiply matrix v by 1+i.

>> (1+i)*v

ans =

[     i,     1]
[ 1 + i, 1 + i]

Those are the eigenvectors we entered.

If you don't have Matlab's Symbolic Toolbox, I did this in the editor.

%%
clear
D=diag([1+i,1-i]);
V=[1,1;1+i,1-i];
A=V*D*inv(V)

And this is the output.

A =

     0     1
    -2     2
David
  • 981
  • 1
  • 15
  • 27