python - finding eigenvector using linalg -


i using linalg.eig numpy find eigenvalues , vectors of matrices. matrix below has single eigenvector of form (t,0). python giving me different results:

>>> = np.matrix('2. 0. ; 1. 2.') >>> print np.linalg.eig(a) (array([ 2.,  2.]), matrix([[  0.00000000e+00,   4.44089210e-16],         [  1.00000000e+00,  -1.00000000e+00]])) 

what wrong?

what expect?

first off, (t, 0) not eigenvector of input matrix:

   | 2.  0.| x |t|  ==> [2t, t]    | 1.  2.|   |0| 

contrast with:

   | 2.  0.| x |0|  ==> [0, 2t] == 2 * [0, t]    | 1.  2.|   |t| 

okay, val = 2, vec = [0, 1] make sense, multiplier thereof.


rounding error

next, keep in mind eig uses iterative approximate solution, analytic solutions eigenvectors aren't possible >3x3 inputs. therefore, can ignore fact 1 value in eigenvectors isn't zero.

your output basically:

eigs = [2, 2] vecs = [[0,  0],         [1, -1]] 

note individual eigenvectors of eig in columns, not rows. in other words, 2 identical eigenvalues of 2 , 2 eigenvectors of [0, 1] , [0, -1].


there can one!

as @warrenweckesser pointed out, defective matrix has 1 eigenvector despite being 2x2.

therefore, mathematically we'd expect val = 2, vec = [0, 1]. instead, pair: val = 2, vec = [0, -1].

so expected 1 eigenvector , got two... possible?

wait, got 2 of same thing!?

as sanity check, note [0, -1] eigenvector of 2x2 input:

   | 2.  0.| x | 0|  ==> [0, -2t] == 2 * [0, -1]    | 1.  2.|   |-t| 

of course, equivalent val = -2, vec = [0, 1], it's same eigenvector.

so why numpy.linalg.eig give 2 output eigenvectors [0, -1] , [0, 1] identical eigenvalues of 2? they're same thing!

in nutshell, np.linalg.eig of mxm matrix guaranteed always return m eigenvalues , vectors.

however, can bit better that. if rule, find 1 , return various multiples of it.


how eig choose eigenvectors/values return?

in general, there infinite number of eigenvectors given matrix, they'll have relationship a * x = lambda * x.

therefore, have program give useful output, need place restrictions. otherwise, need return infinite number of different similar results.

the key how output of np.linalg.eig defined:

  1. the number of output eigenvectors equal size of input (i.e. 3 or 3x3, 4 4x4, etc).
  2. the eigenvectors have unit length.
  3. the output eigenvectors orthogonal, if possible
  4. if there aren't appropriate number of orthogonal eigenvectors, eigenvalues linearly dependent eigenvectors identical.

following rules

okay, we're going 2 eigenvalues , 2 eigenvectors input 2x2, , we'll orthogonal eigenvectors if possible. furthermore, eigenvectors have unit length, limiting eigenvalues get.

however, in case there aren't 2 independent eigenvectors.

what we're seeing fourth rule above coming play. documentation states:

the array v of eigenvectors may not of maximum rank, is, of columns may linearly dependent, although round-off error may obscure fact. if eigenvalues different, theoretically eigenvectors linearly independent.

we know 2 eigenvectors guaranteed produced. text above can infer if they're same vector, indicated making eigenvalues identical.


so in case, have 2x2 matrix 1 eigenvalue/vector of 2 , [0, 1]:

if eigenvalues must identical , eigenvector must have unit length of one, other valid combination val = 2, vec=[0, -1].


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -