#!/usr/bin/perl -w use strict; use PDL; my $v1 = pdl reverse 1..10; my $v2 = pdl 0..9; my $v3 = pdl ((2)x10); my $add = $v1 + $v2; my $mult = $v1 * $add; my $div = $mult / $v3; my $sub = $div - $v1; print "add: $add\nmult: $mult\ndiv: $div\nsub: $sub\n"; # we didn't stomp the original vectors either... # and of course, we can work with matrices too my $matA = pdl [0,0,0],[1,1,1],[2,2,2]; # 2d 3x3 $matA++; # add one across the board $matA *= 2; # and scale up by factor of 2 print "A: $matA\n"; $matA *= $matA; # scale it by itself print "B: $matA\n"; $matA x= $matA; # matrix multiply print "C: $matA\n"; # and say, did you ever want to know the eigenvalues and # eigenvectors of a 4 x 4 matrix of a fibonacci sequence??? use PDL::Slatec; # Fortran never dies :-) my $fibo = fibonacci(4,4); my($eigvals, $eigvecs) = eigsys($fibo); print <