# eigenvectors

8 messages
Open this post in threaded view
|

## eigenvectors

 This may be a dumb question, forgive me, it's been too long. I have a real, square matrix Q and I need to factorize it as         Q = inv(X)*D*X where D is diagonal.  I think that this means that D contains the eigenvalues and X contains the eigenvectors of Q.  Is that right?  How do I get D and X from octave.  The function svd gives the "right and left" eigenvectors for any matrix.  I thought that for square matrices this would mean that it would return X but I was wrong. Sheepishly, Heber   _______________________________________________________________________________ Heber Farnsworth Assistant Professor of Finance John M. Olin School of Business Washington University Campus Box 1133 phone: (314) 935-4221 One Brookings Drive FAX: (314) 935-6359 St. Louis, MO 63130-4899 --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL.  To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------
Open this post in threaded view
|

## Re: eigenvectors

 Ahh, I'd forgotten about the eig function.  I was looking in the help under matrix factorizations and eig wasn't listed.  It's under basic matrix functions. Thanks, On Wed, 9 Jun 1999, Nimrod Mesika wrote: > [hidden email] wrote: > > > >         Q = inv(X)*D*X > > > use   [X,D] = eig(Q); > > D is a diagonal matrix (the elements are the eigenvalues of Q: lambda1, > lambda2, etc..). > X is a matrix of eigenvectors. > > Actually, since octave returns X as a unitary matrix (a matrix for which > inv(A)=A') you also have the simpler expression: > > Q = X' * D * X; > > -- Nimrod. > --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL.  To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------
Open this post in threaded view
|

## Re: eigenvectors

 On  9-Jun-1999, [hidden email] <[hidden email]> wrote: | Ahh, I'd forgotten about the eig function.  I was looking in the help | under matrix factorizations and eig wasn't listed.  It's under basic | matrix functions. Oops.  I think I should move it. | Thanks, | | On Wed, 9 Jun 1999, Nimrod Mesika wrote: | | > [hidden email] wrote: | > > | > >         Q = inv(X)*D*X | > > | > use   [X,D] = eig(Q); | > | > D is a diagonal matrix (the elements are the eigenvalues of Q: lambda1, | > lambda2, etc..). | > X is a matrix of eigenvectors. | > | > Actually, since octave returns X as a unitary matrix (a matrix for which | > inv(A)=A') you also have the simpler expression: | > | > Q = X' * D * X; Except that I think the expression should be   Q = X * D * X' For example, a quick check shows   octave:15> q = hilb (3);   octave:16> [x, d] = eig (q)   x =     -0.12766   0.54745   0.82704      0.71375  -0.52829   0.45986     -0.68867  -0.64901   0.32330   d =     0.00269  0.00000  0.00000     0.00000  0.12233  0.00000     0.00000  0.00000  1.40832   octave:17> x*d*x' - q   ans =       0.0000e+00    0.0000e+00    5.5511e-17       0.0000e+00    0.0000e+00    5.5511e-17       5.5511e-17    5.5511e-17   -5.5511e-17   octave:18> x'*d*x - q   ans =     -0.269717   0.083138  -0.607023      0.083138   0.294810  -0.573999     -0.607023  -0.573999  -0.025093 Also note that this diagonalization can fail if you have repeated eigenvalues.  For example, try q = [1, 2, 3; 0, 1, 2; 0, 0, 3]. jwe --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL.  To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------
Open this post in threaded view
|

## Re: eigenvectors

 Actually neither is correct in general.  In general you have Q = X*D*inv(X) but if Q is symmetric inv(X) = X' Heber On Wed, 9 Jun 1999, John W. Eaton wrote: > On  9-Jun-1999, [hidden email] <[hidden email]> wrote: > > | Ahh, I'd forgotten about the eig function.  I was looking in the help > | under matrix factorizations and eig wasn't listed.  It's under basic > | matrix functions. > > Oops.  I think I should move it. > > | Thanks, > | > | On Wed, 9 Jun 1999, Nimrod Mesika wrote: > | > | > [hidden email] wrote: > | > > > | > >         Q = inv(X)*D*X > | > > > | > use   [X,D] = eig(Q); > | > > | > D is a diagonal matrix (the elements are the eigenvalues of Q: lambda1, > | > lambda2, etc..). > | > X is a matrix of eigenvectors. > | > > | > Actually, since octave returns X as a unitary matrix (a matrix for which > | > inv(A)=A') you also have the simpler expression: > | > > | > Q = X' * D * X; > > Except that I think the expression should be > >   Q = X * D * X' > > For example, a quick check shows > >   octave:15> q = hilb (3); >   octave:16> [x, d] = eig (q) >   x = > >     -0.12766   0.54745   0.82704 >      0.71375  -0.52829   0.45986 >     -0.68867  -0.64901   0.32330 > >   d = > >     0.00269  0.00000  0.00000 >     0.00000  0.12233  0.00000 >     0.00000  0.00000  1.40832 > >   octave:17> x*d*x' - q >   ans = > >       0.0000e+00    0.0000e+00    5.5511e-17 >       0.0000e+00    0.0000e+00    5.5511e-17 >       5.5511e-17    5.5511e-17   -5.5511e-17 > >   octave:18> x'*d*x - q >   ans = > >     -0.269717   0.083138  -0.607023 >      0.083138   0.294810  -0.573999 >     -0.607023  -0.573999  -0.025093 > > > Also note that this diagonalization can fail if you have repeated > eigenvalues.  For example, try q = [1, 2, 3; 0, 1, 2; 0, 0, 3]. > > jwe > > > > --------------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL.  To ensure > that development continues, see www.che.wisc.edu/octave/giftform.html > Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html > --------------------------------------------------------------------- > > --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL.  To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------
Open this post in threaded view
|

## Re: eigenvectors

 In reply to this post by heberf-2 Whoops,  the story is a bit more complicated than that.  Herber Farnsworth wrote: >Ahh, I'd forgotten about the eig function.  I was looking in the help >under matrix factorizations and eig wasn't listed.  It's under basic >matrix functions. > >Thanks, > >On Wed, 9 Jun 1999, Nimrod Mesika wrote: > >> [hidden email] wrote: >> > >> >         Q = inv(X)*D*X >> > >> use   [X,D] = eig(Q); >> >> D is a diagonal matrix (the elements are the eigenvalues of Q: lambda1, >> lambda2, etc..). >> X is a matrix of eigenvectors. >> >> Actually, since octave returns X as a unitary matrix (a matrix for which >>inv(A)=A') you also have the simpler expression: > > > >Q = X' * D * X; > > >> -- Nimrod. > > Actually, it's a bit more complicated than that.  Not every matrix is even   diagonalizable, let alone unitarily diagonalizable.  Any *real symmetric*   matrix, such as a Hilbert matrix, is automatically unitarily (X^{-1}=X')   diagonalizable, whether it has repeated eigenvalues or not. On the other   hand,  a matrix like a = [1,2;0,3] is diagonalizable, but not unitarily   diagonalizable.  Worse yet, a matrix like a = [1,1;0,1] is simply not   diagonalizable at all.  In the first case, octave will return a unitary   matrix.  In the second case, it will return a matrix whose columns are unit   length eigenvectors.  And in the third case it will return a completely   incorrect matrix (none can work) with unit length columns.  BTW, if you do   want to review these linear algebra concepts, I keep a copy of a text I'm   writing on the web in my linear algebra home page   (http://www.math.unl.edu/~tshores/linalgtext.html), so feel free to use it   for a quick reference. Tom Shores --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL.  To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------
Open this post in threaded view
|

## Re: eigenvectors

 In reply to this post by heberf-2 [hidden email] wrote: > > This may be a dumb question, forgive me, it's been too long. > > I have a real, square matrix Q and I need to factorize it as > >         Q = inv(X)*D*X > > where D is diagonal.  I think that this means that D contains the > eigenvalues and X contains the eigenvectors of Q.  Is that right?  How do > I get D and X from octave.  The function svd gives the "right and left" > eigenvectors for any matrix.  I thought that for square matrices this > would mean that it would return X but I was wrong. > > Sheepishly, > Heber > > Well, the problem is that not every matrix can be factorized in that way. In general, what one has is the _Jordan_ form.  Furthermore, the singular value decomposition (svd) is not directly related to your problem. The situation is difficult to explain in just few lines, you may want to consult a linear algebra textbook on the matter. Regards, Eduardo --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL.  To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------