Finding Matrix When Eigen Values & Eigen Vectors were known

146 Views Asked by At

I have been trying to find my matrix from eigenvalues and eigenvectors. I calculated eigen values and eigen vectors from a matrix first. Then, I want to verify the values of eigenvalues and eigenvectors. But the didn't get the expected value. my code

import numpy as np
from numpy.linalg import eig
a=np.array([[1,2],[2,np.pi]])
w,v=eig(a)
c0=np.outer(v[0],v[0].T)
c1=np.outer(v[1],v[1].T)
a_=w[0]*c0+w[1]*c1

the result I got was:

array ([[ 1.     , -2.     ], 
        [-2.     ,  3.14159]])

but I was expecting same array as a. Can anyone tell me what's wrong here?

1

There are 1 best solutions below

0
chrslg On

Eigenvectors of a are not v[0] and v[1]. v is a transformation matrix. So columns of v, that is v[:,0] and v[:,1] are the eigenvectors.

You wrote the code as if v[0] and v[1] were eigenvectors, which they are not.

Also, I expect that you are aware that your code (once replaced v[0] and v[1] by v[:,0] and v[:,1]) only works because v is unitary and therefore v⁻¹ is vᵀ.

Generic way to get back a would be [email protected](w)@np.linalg.inv(v). What you are doing is the equivalent of [email protected](w)@v.T. Which is ok, as long as np.linalg.inv(v) and v.T are the same thing. Which is the case when v is unitary.

Since your initial matrix a is symmetric, then we know that it exists a set of orthogonal eigenvectors, that form, once normalized, an unitary matrix. So, we know that a unitary matrix v is possible.

And because you have 2 different eigenvalues, in dimension 2, then, the vectors had to be orthogonal (each subspace is a line; so whatever eigenvector we choose, they are colinear the the eigenvectors of the orthogonal set we know exist). So in the case where a is symmetric, and you have as many eigenvalues as the dimension of a, v is orthogonal, and unitary, since eig garantees that each vector is normalized (norm 1)

But if a happened to have double eigenvalues, then, all we know is that v COULD be unitary, but eig doesn't guarantees that.

For example, a caricatural example, is A=Identity Unique eigenvalue is 1. And eigenspace is the whole space. So any v made of two independent vectors is a valid v. Sure, there exist some unitary sets of eigenvectors ([1,0], [0,1] is the obvious one. And indeed np.array([[1,0],[0,1]])@np.diag([1,1])@np.array([[1,0],[0,1]]).T) is A. But there also exist others, non unitary, even after normalization. For example, [1,0], [1/√2, 1/√2] is another valid set of eigenvectors that could be returned by eig (both are eigenvectors. They form a valid basis of the eigenspace. And they are normalized).

Yet np.array([[1, 1/np.sqrt(2)], [0, 1/np.sqrt(2)]])@np.diag([1,1])@np.array([[1, 1/np.sqrt(2)], [0, 1/np.sqrt(2)]]).T is not A (np.array([[1, 1/np.sqrt(2)], [0, 1/np.sqrt(2)]])@np.diag([1,1])@np.linalg.inv(np.array([[1, 1/np.sqrt(2)], [0, 1/np.sqrt(2)]])) is).

So, long story short, in dim 2, even with symmetric matrices a, you have no guarantee that v is unitary. Maths tells that it could be. But linalg.eig doesn't guarantee that. And therefore, you don't know if [email protected](w)@v.T (which is what you compute, with longer code) is a.

On the other hand, eigh, which can be used only on hermitian matrices (so, symmetric ones in real world), guarantees that v is unitary.

So tl;dr

  1. Your code assume that v[0] and v[1] are eigenvectors. They are not. v[:,0] and v[:,1] are.

  2. Once that corrected, your code is the equivalent of computing [email protected](w)@v.T

  3. That is the same thing as a (which is equal to [email protected](w)@np.linalg.inv(v)) only if v is unitary. eig doesn't guarantee that it is the case (even if, a being symmetric, it is possible that it is). So, no guarantee that your code will find back a even after correction. Even tho, in your case (after correction) it happens to work.

  4. eigh, which works only with symmetric (hermitians) matrices, as your a is, does guarantees that. So, Replace eig by eigh in your code. And then, you know for sure that (as long as a is symmetric), a_ is a.