Angharad has asked for the wisdom of the Perl Monks concerning the following question:

Hi there
I'm currently trying to get to grips with the PDL module .. i'm wanting to calculate the determinant for a 4x4 matrix. This is the code I've managed to create so far
#!/usr/bin/perl -w use strict; use PDL::MatrixOps; my $mat = pdl [ [3.4603, 1.7529, 1.6990,2.1181], [ 2.5459,2.5615,2.2525,2.3606], [ 2.3606, 2.2515, 2.5628,2.5459], [ 2.1181,1.6982,1.7537,3.4603], ]; my $det = determinant($mat); print "$det\n";
But it comes up with a syntax error
syntax error at ./test.pl line 7, near "pdl [" Execution of ./test.pl aborted due to compilation errors.
Any help much appreciated

Replies are listed 'Best First'.
Re: problem with PDL
by zentara (Cardinal) on Jun 30, 2005 at 12:34 UTC
    You need to "use PDL".
    #!/usr/bin/perl use warnings; use strict; use PDL; use PDL::MatrixOps; ..... ....

    I'm not really a human, but I play one on earth. flash japh
Re: problem with PDL
by marto (Cardinal) on Jun 30, 2005 at 12:16 UTC
    Hi,

    This is untested, but should that read:
    my $mat = PDL::Matrix->pdl [
    Hope this helps.

    Martin
Re: problem with PDL
by Angharad (Pilgrim) on Jun 30, 2005 at 15:25 UTC
    Thanks. Adding use::PDL worked a treat :)
Re: problem with PDL
by anonymized user 468275 (Curate) on Jun 30, 2005 at 12:19 UTC
    ...and then you'll get another syntax error (nothing after the last comma).

    One world, one people

        thanks - I often have to parse perl (e.g. searching and extracting from project code) so now I will have to adjust my rules to allow for unclosed lists.

        One world, one people

      I cannot install PDL at the moment because I'm not on "my" machine, but I was wondering why this should lead to a syntax error.
      ~/sviluppo/perl> cat prova.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $mat = [ [3.4603, 1.7529, 1.6990,2.1181], [ 2.5459,2.5615,2.2525,2.3606], [ 2.3606, 2.2515, 2.5628,2.5459], [ 2.1181,1.6982,1.7537,3.4603], # <-- trailing comma ]; print Dumper($mat); ~/sviluppo/perl> perl prova.pl $VAR1 = [ [ '3.4603', '1.7529', '1.699', '2.1181' ], [ '2.5459', '2.5615', '2.2525', '2.3606' ], [ '2.3606', '2.2515', '2.5628', '2.5459' ], [ '2.1181', '1.6982', '1.7537', '3.4603' ] ];
      Neither errors nor warnings. I think that the list constructor doesn't complain about trailing "hanging" commas because you're able to cut-and-paste lines (like in this example) without the need to treat the last line differently.

      Is it different when PDL comes in?

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Don't fool yourself.