help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eig returns nonorthogonal eigenvectors


From: Nicholas Jankowski
Subject: Re: eig returns nonorthogonal eigenvectors
Date: Tue, 22 Nov 2016 10:02:40 -0500

On Tue, Nov 22, 2016 at 9:49 AM, Nicholas Jankowski <address@hidden> wrote:
On Mon, Nov 21, 2016 at 5:33 PM, chris2 <address@hidden> wrote:
Hello,
  The following commands show a case where octave returns non-orthogonal
eigenvectors.  Mathematically, the eigenvalue is degenerate, so nothing
prohibits this, even for a symmetric matrix, but it would be very useful if
it did.  Is there any way to force octave to orthogonalize the basis?
--thanks, Chris

octave> [q,r]=qr([1, -1, 1, 0; 2, 3, 0, 1; 4, 3, 0, 0; -1, 2, 0, 0])
octave> a=q*diag([5,5,-7,9])*q'
octave> [va,da]=eig(a)
octave> va'*va



not a subject I'm intimately familiar with, but following a similar discussion regarding matlab's eig:
http://stackoverflow.com/questions/33258139/matlab-not-returning-orthonormal-matrix-of-eigenvectors

it seems your non-orthogonal results are the result of numerical precision errors.  From that discussion they mention that eig will return orthogonal eigenvectors if the input is exactly symmetric.  However, from your input after creating a:

Just realized I ran that last set of outputs were with Matlab not Octave. Practically the same results with Octave, the difference only being on the how the numerical error manifested since the two programs use different underlying algorithms.

>> [q,r]=qr([1, -1, 1, 0; 2, 3, 0, 1; 4, 3, 0, 0; -1, 2, 0, 0])
q =

  -2.1320e-001  4.7058e-001  8.5621e-001  1.6837e-017
  -4.2640e-001  -4.5787e-001  1.4547e-001  -7.6641e-001
  -8.5280e-001  -7.6311e-002  -1.7041e-001  4.8771e-001
  2.1320e-001  -7.5039e-001  4.6551e-001  4.1804e-001

r =

  -4.69042  -3.19801  -0.21320  -0.42640
   0.00000  -3.57390   0.47058  -0.45787
   0.00000   0.00000   0.85621   0.14547
   0.00000   0.00000   0.00000  -0.76641

>> a=q*diag([5,5,-7,9])*q'
a =

  -3.7972  -1.4947   1.7509  -4.7829
  -1.4947   7.0956  -1.1977  -2.0942
   1.7509  -1.1977   5.6030   1.7675
  -4.7829  -2.0942   1.7675   3.0986

>>  [va,da]=eig(a)
va =

  -8.5621e-001  -5.1663e-001  1.3128e-001  -1.2608e-017
  -1.4547e-001  2.4109e-001  -6.1966e-001  7.6641e-001
  1.7041e-001  -2.8242e-001  -7.0999e-001  -4.8771e-001
  -4.6551e-001  7.7150e-001  -3.0772e-001  -4.1804e-001

da =

Diagonal Matrix

  -7.0000        0        0        0
        0   5.0000        0        0
        0        0   5.0000        0
        0        0        0   9.0000

>> va'*va
ans =

   1.00000  -0.00000   0.00000   0.00000
  -0.00000   1.00000  -0.25411  -0.00000
   0.00000  -0.25411   1.00000  -0.00000
   0.00000  -0.00000  -0.00000   1.00000

>> a
a =

  -3.7972  -1.4947   1.7509  -4.7829
  -1.4947   7.0956  -1.1977  -2.0942
   1.7509  -1.1977   5.6030   1.7675
  -4.7829  -2.0942   1.7675   3.0986

>> a-a'
ans =

  0.0000e+000  0.0000e+000  0.0000e+000  0.0000e+000
  0.0000e+000  0.0000e+000  0.0000e+000  0.0000e+000
  0.0000e+000  0.0000e+000  0.0000e+000  4.4409e-016
  0.0000e+000  0.0000e+000  -4.4409e-016  0.0000e+000

>> a = (a+a')/2
a =

  -3.7972  -1.4947   1.7509  -4.7829
  -1.4947   7.0956  -1.1977  -2.0942
   1.7509  -1.1977   5.6030   1.7675
  -4.7829  -2.0942   1.7675   3.0986

>> a-a'
ans =

   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0

>> [va,da] = eig(a)
va =

   0.85621  -0.51094   0.07647   0.00000
   0.14547   0.32390   0.53530  -0.76641
  -0.17041  -0.15967   0.84119   0.48771
   0.46551   0.78009   0.00000   0.41804

da =

Diagonal Matrix

  -7.0000        0        0        0
        0   5.0000        0        0
        0        0   5.0000        0
        0        0        0   9.0000

>> va'*va
ans =

  1.0000e+000  -1.1102e-016  -1.3878e-016  -5.5511e-017
  -1.1102e-016  1.0000e+000  8.3267e-017  -1.6653e-016
  -1.3878e-016  8.3267e-017  1.0000e+000  1.1102e-016
  -5.5511e-017  -1.6653e-016  1.1102e-016  1.0000e+000

>> ans-eye(4)
ans =

  8.8818e-016  -1.1102e-016  -1.3878e-016  -5.5511e-017
  -1.1102e-016  0.0000e+000  8.3267e-017  -1.6653e-016
  -1.3878e-016  8.3267e-017  0.0000e+000  1.1102e-016
  -5.5511e-017  -1.6653e-016  1.1102e-016  1.1102e-015


Again, orthoganal to less that 1e-15. Same explanation for the first data even though the small error produced different non-orthogonal values for a in Octave.

nickj

reply via email to

[Prev in Thread] Current Thread [Next in Thread]