# Eigenvalues, eigenvectors in Ruby?

**URL:** <https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754>\
**Category:** Ruby\
**Created:** [November 20, 2007, 11:51am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754 "2007-11-20T11:51:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 11:51am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/1 "2007-11-20T11:51:23Z")

</div>

is there algo allready implemented to find eigenvalues, eigenvectors in  
Ruby ???

for symetrical matrices ?

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 12:43pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/2 "2007-11-20T12:43:12Z")

</div>

Une BÃ©v  
ue wrote:

> is there algo allready implemented to find eigenvalues, eigenvectors in  
> Ruby ???
> 
> for symetrical matrices ?  
> You can use rb-gsl to do that. [http://rb-gsl.rubyforge.org/eigen.html](http://rb-gsl.rubyforge.org/eigen.html)

It is a binding to the gsl library (written in c).

Edwin

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/3 "2007-11-20T13:15:24Z")

</div>

On Nov 20, 12:49 pm, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) (Une  
Bévue) wrote:

> is there algo allready implemented to find eigenvalues, eigenvectors in  
> Ruby ???
> 
> for symetrical matrices ?

Take a look at RNum: [http://rnum.rubyforge.org/](http://rnum.rubyforge.org/)

Ruby Numerical Library is a linear algebra package using Blas and  
Lapack (the highly regarded scientific libraries originally written in  
FORTRAN.)

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 4:34pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/4 "2007-11-20T16:34:31Z")

</div>

Axel E. wrote:

> > –
> 
> Best regards,
> 
> Axel

One of the Summer of Code projects extends Matrix to do most of the  
common matrix operations. Try

[http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix)

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/5 "2007-11-20T16:41:32Z")

</div>

On 11/20/07, Une Bévue [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> is there algo allready implemented to find eigenvalues, eigenvectors in  
> Ruby ???
> 
> for symetrical matrices ?

Like several have already said, if you’re doing numerical work - you  
should use something besides the matrix lib in the stdlib.

For yet another working suggestion, NArray has an extension to do  
eigenvalues and eigenvectors based on lapack.

[http://narray.rubyforge.org/](http://narray.rubyforge.org/)  
(ext is called na\_geev, it’s also available on that page)

It’s worked for me.

Cameron

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/6 "2007-11-20T16:27:54Z")

</div>

-------- Original-Nachricht --------

> Datum: Tue, 20 Nov 2007 19:50:14 +0900  
> Von: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: [Matrix] eigenvalues, eigenvectors in Ruby ???

> is there algo allready implemented to find eigenvalues, eigenvectors in  
> Ruby ???
> 
> ## for symetrical matrices ?
> 
> Une Bévue

As far as I know, there is nothing like that in the “matrix.rb” Matrix  
class, but you can find this information by using Ruby bindings to GSL

[http://rb-gsl.rubyforge.org/](http://rb-gsl.rubyforge.org/)

or, alternatively, via the bindings to the R statistical language,

[http://raa.ruby-lang.org/project/rsruby/](http://raa.ruby-lang.org/project/rsruby/)

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/7 "2007-11-20T16:48:34Z")

</div>

On 11/20/07, M. Edward (Ed) Borasky [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> One of the Summer of Code projects extends Matrix to do most of the  
> common matrix operations. Try
> 
> [http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix)

That’s kind of neat, I missed it. Thanks.

Do you know right off how its accuracy compares to GSL/LAPACK routines?

Cameron

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/8 "2007-11-20T20:11:05Z")

</div>

Alex S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Lapack (the highly regarded scientific libraries originally written in  
> FORTRAN.)
> 
> –  
> Alex

ok, fine thanks, to both !

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/9 "2007-11-20T20:35:44Z")

</div>

Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Am I wrong in thinking that you can use that library without being  
> forced to calculate in Floats, i.e. can one use Rationals, Sqrts,  
> continued fractions, whatever as matrix entries ?

yes i had this prob with gsl, my matrices (coming from chemistry then  
having only integer numbers…) print out with -0.000e+00 for 0 and  
1.000e+00 for 1 …)

I’ll try it asap ( [http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix) ) because the  
readme says :

The project consists of some enhancements to the Ruby “Matrix” module  
and includes: LU and QR (Householder, Givens, Gram Schmidt, Hessenberg)  
decompositions, bidiagonalization, eigenvalue and eigenvector  
-----------------------------------^^^^^^^^^^^----^^^^^^^^^^^  
calculations.

i need also permutation matrices, whose i didn’t understood in gsl…

anyway, thanks a lot !!!

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 5:22pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/10 "2007-11-20T17:22:10Z")

</div>

-------- Original-Nachricht --------

> Datum: Wed, 21 Nov 2007 00:47:45 +0900  
> Von: “Cameron McBride” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

> On 11/20/07, M. Edward (Ed) Borasky [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > One of the Summer of Code projects extends Matrix to do most of the  
> > common matrix operations. Try
> > 
> > [http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix)

Dear Ed and Cameron,

> That’s kind of neat, I missed it. Thanks.

Me too. Very nice.

> Do you know right off how its accuracy compares to GSL/LAPACK routines?

Am I wrong in thinking that you can use that library without being  
forced to calculate in Floats, i.e. can one use Rationals, Sqrts,  
continued fractions, whatever as matrix entries ?

Then, its accuracy should only be limited by the space available on  
the machine.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 8:37pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/11 "2007-11-20T20:37:33Z")

</div>

Cameron McBride [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> For yet another working suggestion, NArray has an extension to do  
> eigenvalues and eigenvectors based on lapack.

OK, fine thanks, i’ve a lot a orking solution right now…

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 20, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/12 "2007-11-20T21:12:07Z")

</div>

On Nov 20, 2007 2:35 PM, Une Bévue  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Am I wrong in thinking that you can use that library without being  
> > forced to calculate in Floats, i.e. can one use Rationals, Sqrts,  
> > continued fractions, whatever as matrix entries ?
> 
> yes i had this prob with gsl, my matrices (coming from chemistry then  
> having only integer numbers…) print out with -0.000e+00 for 0 and  
> 1.000e+00 for 1 …)

To be clear, the printing accuracy isn’t the machine accuracy. The  
-0.000e+00 is just the specific  
format that the GSL::Matrix object uses for printing.

Also, the default matrix in GSL is a double (float) based one. You  
can create integer matricies. Look at the manual.

Cameron

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 12:54am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/13 "2007-11-21T00:54:47Z")

</div>

-------- Original-Nachricht --------

> Datum: Wed, 21 Nov 2007 04:35:00 +0900  
> Von: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

> Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Am I wrong in thinking that you can use that library without being  
> > forced to calculate in Floats, i.e. can one use Rationals, Sqrts,  
> > continued fractions, whatever as matrix entries ?
> 
> yes i had this prob with gsl, my matrices (coming from chemistry then  
> having only integer numbers…) print out with -0.000e+00 for 0 and  
> 1.000e+00 for 1 …)

That’s because GSL internally calculates with double precision numbers,  
which cannot represent every number correctly, as not every number  
is a sum of positive and negative powers of 2. But you can always  
round to whole numbers …

> i need also permutation matrices, whose i didn’t understood in gsl…

Have a look at the example on the Wikipedia article.

> **[Permutation matrix](https://en.wikipedia.org/wiki/Permutation_matrix#Examples)**
>
> In mathematics, particularly in matrix theory, a permutation matrix is a square binary matrix that has exactly one entry of 1 in each row and each column with all other entries 0.: 26  An .mw-parser-output .texhtml{font-family:"Nimbus Roman No9 L","Times New Roman",Times,serif;font-size:118%;line-height:1;font-variant-numeric:lining-nums tabular-nums;font-kerning:none}.mw-parser-output .texhtml .texhtml{font-size:100%}.mw-parser-output .texhtml-big{font-size:165%}.mw-parser-output .mvar{font-s E...

A permutation matrix has exactly one 1 entry in every row, at the  
place that the permutation vector indicates (note that Ruby starts  
counting at 0, so the permutation vector given in the Wikipedia article  
should actually be (0 3 1 4 2)), the remaining entries are 0.  
The reason to associate a vector and a matrix like this is that  
due to the way multiplication of matrices is defined, multiplying

permutation\_matrix\*matrix

gives you the column vectors of ‘matrix’ shuffled as the permutation  
vector indicates, i.e.  
the matrix (inner arrays=rows)

[[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3],[4,4,4,4,4],[5,5,5,5,5]]

would be mapped to

[[1,1,1,1,1],[4,4,4,4,4],[2,2,2,2,2],[5,5,5,5,5],[3,3,3,3,3]]

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 10:00am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/14 "2007-11-21T10:00:54Z")

</div>

M. Edward (Ed) Borasky [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> One of the Summer of Code projects extends Matrix to do most of the  
> common matrix operations. Try
> 
> [http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix)

I’ve downloadd it, how do I install it ?  
I’ve found this only file (except docs) :  
/opt/local/lib/ruby/1.8/matrix.rb

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 1:25am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/15 "2007-11-21T01:25:46Z")

</div>

Axel E. wrote:

> > > [http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix)  
> > > Am I wrong in thinking that you can use that library without being  
> > > forced to calculate in Floats, i.e. can one use Rationals, Sqrts,  
> > > continued fractions, whatever as matrix entries ?
> 
> Then, its accuracy should only be limited by the space available on  
> the machine.
> 
> Best regards,
> 
> Axel

Yes, one of the design goals was to support Rational arithmetic. But  
unless the matrix is poorly-conditioned, you shouldn’t have to do so,  
and for real symmetric eigensolutions, the only problem with using  
floating arithmetic would be if you have some pathologically close  
eigenvalues you need to separate.

I don’t know about continued fractions … I don’t think that’s in  
there. If you want to do that, you’ll need something like Maxima, Axiom  
or Yacas. Or a special-purpose exact linear algebra library.

Anybody up to do a Ruby binding to Yacas? There’s an R binding to it, so  
it can’t be too difficult. There are also Java hooks, so this may be yet  
another JRuby killer app. 🙂

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 10:05am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/16 "2007-11-21T10:05:35Z")

</div>

Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Have a look at the example on the Wikipedia article.  
> [Permutation matrix - Wikipedia](http://en.wikipedia.org/wiki/Permutation_matrix#Examples)

YES, that’s the one i’ve followed…

> gives you the column vectors of ‘matrix’ shuffled as the permutation  
> vector indicates, i.e.  
> the matrix (inner arrays=rows)
> 
> [[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3],[4,4,4,4,4],[5,5,5,5,5]]
> 
> would be mapped to
> 
> [[1,1,1,1,1],[4,4,4,4,4],[2,2,2,2,2],[5,5,5,5,5],[3,3,3,3,3]]

i see, now why permutation isn’t a matrix like that :

0 0 1 0  
0 0 0 1  
1 0 0 0  
0 1 0 0

but rather a vector indicating the permutations to be done…

thanks a lot !

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/17 "2007-11-21T12:28:06Z")

</div>

-------- Original-Nachricht --------

> Datum: Wed, 21 Nov 2007 18:00:04 +0900  
> Von: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

> M. Edward (Ed) Borasky [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > One of the Summer of Code projects extends Matrix to do most of the  
> > common matrix operations. Try
> > 
> > [http://rubyforge.org/projects/matrix](http://rubyforge.org/projects/matrix)
> 
> I’ve downloadd it, how do I install it ?  
> I’ve found this only file (except docs) :

> /opt/local/lib/ruby/1.8/matrix.rb
> 
> –  
> Une Bévue

You should just require it : require “matrix”.  
Since there is already a matrix.rb in the standard library,  
make sure you require the right one - an alternative would  
be to rename the matrix.rb file with the extended functionality and keep  
the old.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 12:32pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/18 "2007-11-21T12:32:47Z")

</div>

-------- Original-Nachricht --------

> Datum: Wed, 21 Nov 2007 09:25:09 +0900  
> Von: “M. Edward (Ed) Borasky” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

> > > >
> 
> Anybody up to do a Ruby binding to Yacas? There’s an R binding to it, so  
> it can’t be too difficult. There are also Java hooks, so this may be yet  
> another JRuby killer app. 🙂

Dear Ed,

it’s very good that one doesn’t have to do every calculation in  
Float or Double .. of course, Rationals and Symbolic computations can  
become very complex, but if one needs to do it,  
it’s nice to know that Ruby has an option that can help.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 21, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/19 "2007-11-21T14:13:28Z")

</div>

M. Edward (Ed) Borasky wrote:

> I don’t know about continued fractions … I don’t think that’s in  
> there. If you want to do that, you’ll need something like Maxima, Axiom  
> or Yacas. Or a special-purpose exact linear algebra library.
> 
> Anybody up to do a Ruby binding to Yacas? There’s an R binding to it, so  
> it can’t be too difficult. There are also Java hooks, so this may be yet  
> another JRuby killer app. 🙂

You can talk to maxima quite easily, because maxima can start as a  
server/daemon, allowing you to just send commands to it via a socket  
(and read the results).

Edwin

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [November 22, 2007, 9:06am UTC](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754/20 "2007-11-22T09:06:01Z")

</div>

Cameron McBride [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Do you know right off how its accuracy compares to GSL/LAPACK routines?

I don’t know, however i found a discreapency between GSL and  
extendedMatrix for eigenvectors :

require ‘extendmatrix.rb’

a = Matrix[[ 0, 1, 1, 0],  
[1, 0, 1, 0],  
[1, 1, 0, 1],  
[0, 0, 1, 0] ]

p a.det

# =\> 2

p a.trace

# =\> 0

p a.eigenvaluesJacobi

# Vector[-1.0, 2.17008648662603, -1.48119430409202, 0.311107817465982]

# GSL : a.eigval = [2.170e+00 3.111e-01 -1.000e+00 -1.481e+00]

p a.cJacobiV  
=begin  
Matrix[[0.707106781186547, 0.522720725656538, -0.302028136647909,  
-0.368160355880552],  
[-0.707106781186547, 0.522720725656538, -0.302028136647909,  
-0.368160355880552],  
[0.0, 0.611628457346727, 0.749390492326316, 0.253622791118195],  
[0.0, 0.281845198827065, -0.505936655478633, 0.815224744804294]]  
GSL : a.eigvec =  
[ 5.227e-01 3.682e-01 -7.071e-01 3.020e-01  
5.227e-01 3.682e-01 7.071e-01 3.020e-01  
6.116e-01 -2.536e-01 -9.158e-16 -7.494e-01  
2.818e-01 -8.152e-01 4.852e-16 5.059e-01 ]  
=end

the eigenvalues are “the same” however eigenvectors doesn’t have even  
the same sign to within a multiplicative constant ???

what did i miss this morning ?  
a cofee cup ??

[Next page](https://www.ruby-forum.com/t/eigenvalues-eigenvectors-in-ruby/120754.md?page=2)
