MATLAB Incorrectly Calculating Eigenvalues of Unitary Matrix

In summary, the speaker is discussing their experience with finding eigenvalues of a matrix with both real and complex numbers in MATLAB. They provide an example of a matrix A and its corresponding eigenvalues, but mention that the eigenvalues do not have an absolute value of 1 as expected for a unitary matrix. They also mention that MATLAB fails to confirm A as unitary. The speaker suggests using the ctranspose(A)*A method to get the identity matrix instead of finding the Hermitian conjugate.
  • #1
ColdFusion85
142
0
This is a MATLAB question. I am trying to find the eigenvalues of a matrix with both real and complex numbers. This is my session.

>> A=[1/sqrt(2),i/sqrt(2),0; -1/sqrt(2),i/sqrt(2),0; 0,0,1]

A =

0.7071, 0 + 0.7071i, 0
-0.7071, 0 + 0.7071i, 0
0, 0, 1.0000

>> eig(A)

ans =

0.9659 - 0.2588i
-0.2588 + 0.9659i
1.0000

However, matrix A is unitary, so [tex]|\lambda|[/tex] should equal 1. This is true for the third eigenvalue, but not for the other two. I even noticed that MATLAB fails to confirm A is unitary:

A =

0.7071, 0 + 0.7071i, 0
-0.7071, 0 + 0.7071i, 0
0, 0, 1.0000

>> B=[1/sqrt(2),-1/sqrt(2),0; i/sqrt(2),i/sqrt(2),0;0,0,1]

B =

0.7071, -0.7071, 0
0 + 0.7071i, 0 + 0.7071i, 0
0, 0, 1.0000

>> A*B

ans =

0, -1, 0
-1, 0, 0
0 , 0, 1

Why is MATLAB giving me incorrect answers? It was even doing this for me yesterday when I was dealing with real matricies. It was giving me eigenvalues with imaginary components when they were, in fact, all real. What's the deal?
 
Physics news on Phys.org
  • #2
ColdFusion85 said:
However, matrix A is unitary, so |\lambda| should equal 1. This is true for the third eigenvalue, but not for the other two.
Have you checked using the abs function for each eigenvalue? I get 1 on checking for each eigenvalue.
ColdFusion85 said:
I even noticed that MATLAB fails to confirm A is unitary
Are you trying to find the Hermitian conjugate of A and multiplying A with it to get I? Don't do it like that. Use ctranspose(A)*A. You'll surely get the identity matrix.
 

FAQ: MATLAB Incorrectly Calculating Eigenvalues of Unitary Matrix

1. Why is MATLAB incorrectly calculating eigenvalues of a unitary matrix?

MATLAB uses numerical algorithms to calculate eigenvalues, which may lead to rounding errors and inaccuracies in the results. This can happen especially with unitary matrices, which have very small eigenvalues that may be rounded to zero.

2. How can I check if MATLAB has correctly calculated the eigenvalues of a unitary matrix?

One way to check is by calculating the determinant of the matrix, as the product of the eigenvalues should be equal to the determinant. Another way is to compare the eigenvalues calculated by MATLAB with those obtained from a different software or by hand calculation.

3. Can I improve the accuracy of MATLAB's eigenvalue calculation for unitary matrices?

Yes, you can use the eig function with the option 'nobalance', which avoids balancing the matrix and may lead to more accurate results. You can also try increasing the precision of the calculations by using the vpa function.

4. Is there a specific scenario where MATLAB is more likely to incorrectly calculate the eigenvalues of a unitary matrix?

In general, MATLAB may have difficulties with unitary matrices that have eigenvalues that are very close to zero. This can happen, for example, when the matrix is ill-conditioned or when the eigenvalues are very small compared to the other elements of the matrix.

5. What other factors can affect the accuracy of MATLAB's eigenvalue calculation for unitary matrices?

Besides the precision of the calculations and the properties of the matrix itself, the choice of the algorithm and the implementation of the eig function may also impact the accuracy of the results. Additionally, any programming errors or mistakes in the input data can also lead to incorrect eigenvalues.

Back
Top