0

I looked at the eigenvector matrix of a given matrix, but when I try to inverse it I have an error in eigenvector_matrix_inv().

require 'matrix'

m = Matrix[ [0.5703125, 1.8369140625, 0.0, 0.0], 
            [-0.6875, -0.4609375, 0.0, 0.0], 
            [0.0, 0.0, -2.1796875, 8.7119140625], 
            [0.0, 0.0, -0.6875, 2.2890625] ]

meigen = m.eigen.eigenvector_matrix
meiveni = m.eigen.eigenvector_matrix_inv
# .../matrix.rb:930:in `block in inverse_from': Not Regular Matrix (ExceptionForMatrix::ErrNotRegular)

It should not be singular, as checked with Mathematica:

mruby = {{0.5703125, 1.8369140625, 0.0, 0.0}, {-0.6875, -0.4609375, 
0.0, 0.0}, {0.0, 0.0, -2.1796875, 8.7119140625}, {0.0, 
0.0, -0.6875, 2.2890625}};
Inverse[Eigenvectors[mruby]]

giving

{{0.586146 - 0.302685 I, 0.586146 + 0.302685 I, 0. + 0. I, 
0. + 0. I}, {0. - 1.07831 I, 0. + 1.07831 I, 0. + 0. I, 
0. + 0. I}, {0. + 0. I, 0. + 0. I, 0.519354 + 1.16217 I, 
0.519354 - 1.16217 I}, {0. + 0. I, 0. + 0. I, 0. - 4.53135 I, 
0. + 4.53135 I}}

What am I doing wrong ?

Should I take special care of something particular in Ruby ?

Amir
  • 10,600
  • 9
  • 48
  • 75
Cedric H.
  • 7,980
  • 10
  • 55
  • 82

1 Answers1

0

You don't invert a matrix when you do eigenvalue problems. There are lots of algorithms, but inversion isn't one of them.

Your matrix is a bit odd: You've got two positive and two negative diagonal elements. I think the eigenvectors having complex entries suggests that it's not what you'd usually have: real eigenvalues with real eigenvectors.

Either your matrix is incorrect or you've chosen the wrong algorithm. See if a Hessian matrix is what you have and look at appropriate algorithms.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I want complex conjugate eigenvalues, that's not the problem. The question is : why does Ruby complain ? – Cedric H. Sep 21 '12 at 08:35
  • Check the algorithm that Ruby is using underneath the covers. It might not be suitable for this kind of matrix. – duffymo Sep 21 '12 at 09:49