is there algo allready implemented to find eigenvalues, eigenvectors in

Ruby ???

for symetrical matrices ?

is there algo allready implemented to find eigenvalues, eigenvectors in

Ruby ???

for symetrical matrices ?

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

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

Edwin

On Nov 20, 12:49 pm, [email protected] (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/

Ruby Numerical Library is a linear algebra package using Blas and

Lapack (the highly regarded scientific libraries originally written in

FORTRAN.)

Axel E. wrote:

–

Best regards,

Axel

One of the Summer of Code projects extends Matrix to do most of the

common matrix operations. Try

On 11/20/07, Une Bévue [email protected] 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/

(ext is called na_geev, it’s also available on that page)

It’s worked for me.

Cameron

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

Datum: Tue, 20 Nov 2007 19:50:14 +0900

Von: [email protected]

An: [email protected]

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

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

http://raa.ruby-lang.org/project/rsruby/

Best regards,

Axel

On 11/20/07, M. Edward (Ed) Borasky [email protected] wrote:

One of the Summer of Code projects extends Matrix to do most of the

common matrix operations. Try

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

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

Cameron

Alex S. [email protected] wrote:

Lapack (the highly regarded scientific libraries originally written in

FORTRAN.)–

Alex

ok, fine thanks, to both !

Axel E. [email protected] 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 ) 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 !!!

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

Datum: Wed, 21 Nov 2007 00:47:45 +0900

Von: “Cameron McBride” [email protected]

An: [email protected]

Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

On 11/20/07, M. Edward (Ed) Borasky [email protected] wrote:

One of the Summer of Code projects extends Matrix to do most of the

common matrix operations. Try

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

Cameron McBride [email protected] 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…

On Nov 20, 2007 2:35 PM, Une Bévue

[email protected] 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

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

Datum: Wed, 21 Nov 2007 04:35:00 +0900

Von: [email protected]

An: [email protected]

Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

Axel E. [email protected] wrote:

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.

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

M. Edward (Ed) Borasky [email protected] wrote:

One of the Summer of Code projects extends Matrix to do most of the

common matrix operations. Try

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

Axel E. wrote:

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.

Axel E. [email protected] wrote:

Have a look at the example on the Wikipedia article.

Permutation matrix - Wikipedia

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 !

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

Datum: Wed, 21 Nov 2007 18:00:04 +0900

Von: [email protected]

An: [email protected]

Betreff: Re: [Matrix] eigenvalues, eigenvectors in Ruby ???

M. Edward (Ed) Borasky [email protected] wrote:

One of the Summer of Code projects extends Matrix to do most of the

common matrix operations. TryI’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

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

Datum: Wed, 21 Nov 2007 09:25:09 +0900

Von: “M. Edward (Ed) Borasky” [email protected]

An: [email protected]

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

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

Cameron McBride [email protected] 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

p a.trace

p a.eigenvaluesJacobi

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 ??

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs