Search code examples
matlabeigenvalue

Eigenvalues using eig


I have a simple 2x2 matrix:

A = [-2.0883*10^7 , 1.3975*10^7 ; 1.3975*10^7 , -9.3514*10^6]

by using eig(A) I got the following eigenvalues:

(-3.0235*10^7, -9.3132*10^-10)

However, by using some other calculators on the web I obtain this answer:

(-3.0235*10^7 , 507.32)

What should I do in Matlab to obtain the eigenvalues like in the second result?

Example of result:

enter image description here

Thank you.


Solution

  • The eigenvalues at least as mathematical constructs are completely well-defined and unambiguous (except for their order). If the eigenvalues are off this either means that one of the results is wrong, or the matrix is so ill-conditioned that eigenvalue solvers don't always give the correct (exact) result.

    In your case you must have misread something:

    >> A = [-2.0883*10^7 , 1.3975*10^7 ; 1.3975*10^7 , -9.3514*10^6];
    >> eigvals = eig(A);
    >> eigvals(1)
    
    ans =
    
      -3.0235e+07
    
    >> eigvals(2)
    
    ans =
    
      507.3209
    

    That is, the second set of eigenvalues is correct.


    Regarding your update:

    For 2x2 matrices the eigenvalues can easily be computed on paper. The two eigenvalues happen to be

    e1 = trace(A)/2 + sqrt(trace(A)^2/4 - det(A))
    e2 = trace(A)/2 - sqrt(trace(A)^2/4 - det(A))
    

    if you solve the second-degree characteristic polynomial. For your exact numbers:

    >> tr = A(1,1) + A(2,2); % computed by hand to avoid magic
    >> d = A(1,1)*A(2,2) - A(1,2)*A(2,1); % same
    >> tr/2 + sqrt(tr^2/4 - d)
    
    ans =
    
      507.3209
    
    >> tr/2 - sqrt(tr^2/4 - d)
    
    ans =
    
      -3.0235e+07
    

    However, your updated code shows that your input isn't exactly what your example is; your true input comes from an earlier calculation and A above is only a truncated version of the floats in the matrix. Now, look at the two terms appearing in the eigenvalues:

    >> format long
    >> tr/2            
    
    ans =
    
       -15117200
    
    >> sqrt(tr^2/4 - d)
    
    ans =
    
         1.511770732088699e+07
    

    As you can see, one term is -15117200 (exact), the other is 15117707.32088699 (approximate; coming from a square root). Now, these numbers are huge in magnitude and almost the same (except a sign). This means their sum will experience cancellation, and this cancellation will be very sensitive to the specific values of the variables.

    In other words, your specific G2{1} contains values such that the above two terms cancel almost exactly, due to some underlying symmetry. Believe what MATLAB is telling you, your eigenvalues are fine. But when you copied a truncated version of the matrix into a separate eigenvalue computation (just like I did above), you got the wrong result due to the cancellation being only partial.


    You gave more specific values of your matrix in a comment:

    >> B = [-2.088317534729117e+07, 1.397451196178947e+07 ; 1.397451196178947e+07 , -9.351402807405353e+06];
    >> tr = trace(B);         
    >> d = det(B);
    >> tr/2
    
    ans =
    
        -1.511728907734826e+07
    
    >> sqrt(tr^2/4 - d)
    
    ans =
    
         1.511728907734826e+07
    

    Mystery solved.