Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl & Math: A Quick Reference

by chunlou (Curate)
on Aug 16, 2003 at 10:21 UTC ( [id://284324]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use Math::Cephes::Matrix qw(mat);
    $a = mat [[1, 2], [3, 4]];
    ...
    print "@{$a->mul($b)}";
    # print "3 7"
    
  2. or download this
    use  Math::MatrixReal;
    $a = Math::MatrixReal->new_from_rows( [[1, 2], [3, 4]] );
    ...
    # print "[  3.000000000000E+000 ]
    #        [  7.000000000000E+000 ]"
    
  3. or download this
    use PDL;
    $a = pdl [[1, 2],[3, 4]];
    ...
    #         [7]
    #        ]"
    
  4. or download this
    >> a = [1, 2; 3, 4];
    >> b = [1; 1];
    ...
            3
            7
    
  5. or download this
    > a = matrix(c(1,2,3,4), ncol=2, byrow=T)
    > b = matrix(c(1,1), ncol=1)
    ...
    [1,]    3
    [2,]    7
    
  6. or download this
    use Math::Cephes::Matrix qw(mat);
    $mat = mat [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
    ...
    # print "5 6
    #        8 9"
    
  7. or download this
    use  Math::MatrixReal;
    $mat = Math::MatrixReal->new_from_rows( 
    ...
    # print "5 6
    #        8 9"
    
  8. or download this
    use PDL;
    $mat = pdl [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
    ...
    #         [8 9]
    #        ]"
    
  9. or download this
    mat = [1,2,3; 4,5,6; 7,8,9];
    mat(2:3, 2:3)
    ...
            5        6
            8        9
    
  10. or download this
    > mat = matrix(1:9, ncol=3, byrow=T)
    > mat[2:3, 2:3]
    ...
    [1,]    5    6
    [2,]    8    9
    
  11. or download this
    > vec = 1:10
    > vec
    ...
    [1] 1 3 5 7 9
    > vec[vec %% 2 == 1] + 1
    [1]  2  4  6  8 10
    
  12. or download this
    #! /usr/local/bin/perl -w
    use strict;
    ...
    ciphered: 18431 6512 5843 7236
    deciphered: 80 101 114 108
    decoded: Perl
    
  13. or download this
    #! /usr/local/bin/perl -w
    use strict ;
    ...
        $Rscript =~ s/<-/=/gm ; # \r or <- will break "echo"
        return `echo $Rscript | $Rcmd` ;
    }
    
  14. or download this
    my $dir = 'D:\\tmp\\prog\\math\\lp32';
    my $lp_solve = "d:\\mydir\\lp_solve.exe";
    ...
    print $lp;
    print $output;
    system("del $lpfile");
    
  15. or download this
    use strict;
    use warnings;
    ...
    matrixreal 5.28/s         --       -94%       -99%
    cephes     83.3/s      1479%         --       -87%
    pdl         625/s     11744%       650%         --
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://284324]
Approved by dorko
Front-paged by valdez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found