Math::Matrix anyone?
GeoBoater
created: 2006-08-02 14:05:07
Oh wisest perl monks,

I'm trying to do some oh-so-simple matrix calculations with Math::Matrix, but the usage of the major functions (cross_product, dot_product, etc) are poorly documented on CPAN, so I'm not sure if I'm even calling them properly.
http://search.cpan.org/~ulpfr/Math-Matrix-0.5/Matrix.pm

Most other functions work, such as print, transpose, etc, but none of the more useful algorithms return anything.

Does anyone have any experience with this? Am I even asking in the right forum?

Here's what I've tried so far:
#! /usr/bin/perl

        use Math::Matrix;

        $a = new Math::Matrix ([1], [2], [3]);
        $x = new Math::Matrix ([4], [5], [6]);

        $a->print("A\n");
        $x->print("X\n");

        $f = $a->cross_product( $x );
        print "output of a->cross_product( x ) is: '$f'\n\n";
        if( defined( $f ) ) { $f->print( "Cross product is \n" ) };

        $f = $a->cross_product( $a, $x );
        print "output of a->cross_product( a, x ) is: '$f'\n\n";
        if( defined( $f ) ) { $f->print( "Cross product is \n" ) };


Script outputs:
$ mathtest.pl 
A
   1.00000 
   2.00000 
   3.00000 
X
   4.00000 
   5.00000 
   6.00000 
output of a->cross_product( x ) is: ''

output of a->cross_product( a, x ) is: ''

Any help would be much appreciated. Thanks!!

Ryan
Re: Math::Matrix anyone?
created: 2006-08-02 14:48:47
I'm not sure about that particular module, but if you can't get it to work you might want to try PDL, which is very well documented and supported although it contains a lot of extra functionality you might not need. In particular check PDL::Primitive for the cross and dot product functions after you've read PDL::Impatient so you understand the basics.
Re: Math::Matrix anyone?
created: 2006-08-02 15:48:16
I think [cpan://Math-VectorReal] will work better for you.
#!/usr/bin/perl
use warnings;
use strict;
use Math::VectorReal;

my $a = vector( 1, 2, 3 );
my $b = vector( 4, 5, 6 );

print "Vector as string (MatrixReal default format)\n\$a => ", $a;
print $a->stringify( "Formated Output   \$a => { %g, %g, %g }\n" );

print "Vector as string (MatrixReal default format)\n\$b => ", $b;
print $b->stringify( "Formated Output   \$b => { %g, %g, %g }\n" );

print 'dot product $a . $b =', $a . $b, "\n\n";
print 'cross product $a x $b =', $a x $b, "\n\n";



I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re^2: Math::Matrix anyone?
created: 2006-08-02 17:10:55
Thanks. I'll give that a try!

Ryan
Re: Math::Matrix anyone? (source)
tye
created: 2006-08-02 16:43:15

You do realize that you have full access to the source code, right?

sub cross_product {
  my $vectors = shift;
  my $class = ref($vectors);

  my $dimensions = @{$vectors->[0]};
  return undef
    unless $dimensions == @$vectors + 1;

indicates that cross_product() expects to receive a single (blessed) matrix that contains the vectors to be productizedmultiplied.

I'm not saying that this access excuses unclear documentation, of course. But I suspect you can use the source to answer your own questions faster then you'll get answers from someone else. Producing a patch for the module might be a good result of your investigation.

- [tye]        

Re^2: Math::Matrix anyone? (source)
created: 2006-08-02 17:21:19
I know, I know. I gave the source code a quick look, didn't quite understand all of what it was doing (being a lowly noobie perl programmer) and begged for help here. Maybe if I have time I'll go back and play around with it.

Thanks.

Ryan

perlmonks.org content © perlmonks.org and dirving, GeoBoater, tye, zentara

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03