Syntactic Confectionery Delight PerlMonks

### Perl & Math: A Quick Reference

by chunlou (Curate)
 on Aug 16, 2003 at 10:21 UTC Need Help??

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

Create A New User
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? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2020-12-02 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How often do you use taint mode?

Results (44 votes). Check out past polls.

Notices?