python-3.xnumpywolfram-mathematicalinear-algebrawolframalpha

numpy and Wolfram Alpha give different eigenvectors


For the following matrix, I tried to get eigen values and eigenvectors from Numpy and Wolfram Alpha, respectively. The eigen values are the same, but the eigenvectors are different.

Results from Numpy:

In [36]: aa
Out[36]: 
array([[10, 14],
       [14, 20]])

In [37]: eigvals, eigvectors = np.linalg.eig(aa)

In [38]: eigvals
Out[38]: array([ 0.13393125, 29.86606875])

In [39]: eigvectors
Out[39]: 
array([[-0.81741556, -0.57604844],
       [ 0.57604844, -0.81741556]])

Results from Wlfram Alpha (prompt: ((10, 14), (14, 20)), solve the eigenvalues and eigenvectors): enter image description here

As you can see, the eigenvalues are the same from two software, but the eigenvectors are different. Aren't the eigenvectors supposed to the same, too? Could someone clarify? Thank you!


Solution

  • Eigenvectors can be scaled up or down as their magnitude does not matter.

    The preferred way to show eigenvectors is as unit vectors which is what numpy produces. The reason it is preferred is that it makes diagonalizing the source matrix easier if the matrix of eigenvectors as columns is orthonormal.

    X = | -√(1/2 + 5√221/442)  -√(1/2 - 5√221/442) | = | -0.8174   -0.5760 |
        |  √(1/2 - 5√221/442)  -√(1/2 + 5√221/442) |   |  0.5760   -0.8174 |
    

    The results from wolfram have chosen a different scaling for each eigenvector with the last element being 1.

    X = | √221/14 - 5/14    -√221/14 - 5/14 | = | 0.7047   -1.4190 |
        |       1                  1        |   | 1.0000    1.0000 |
    

    Both results are correct because both can diagonalize the original matrix. You can check this with

    D = inv(X) * | 10 14 | * X = | 15 - √221      0      | = |0.1339   0.0000 |
                 | 14 20 |       |    0        15 + √221 |   |0.0000  29.8660 |
    

    which is a diagonal matrix with the eigenvalues in the diagonal elements.


    It seems wolfram does a symbolic manipulation, which for the 2×2 matrix

    A = | A11  A12 |
        | A21  A22 |
    

    produces the eigenvectors symbolically by solving a system of equations and setting the last coordinate equals one.

    X = | (D+A11+2*A12-A22)/(D-A11+2*A21+A22) (D-A11-2*A12+A22)/(D+A11-2*A21-A22) |
        |                                   1                                   1 |
    

    with D = √(4*A12*A21 + (A11-A22)^2) > 0