The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Matrix

3*3 matrix manipulation

PhilipRBrenan@yahoo.com, 2004, Perl License

Synopsis

Example t/matrix.t

 #_ Matrix _____________________________________________________________
 # Test 3*3 matrices    
 # philiprbrenan@yahoo.com, 2004, Perl License    
 #______________________________________________________________________
 
 use Math::Zap::Matrix identity=>i;
 use Math::Zap::Vector;
 use Test::Simple tests=>8;
 
 my ($a, $b, $c, $v);
 
 $a = matrix
  (8, 0, 0,
   0, 8, 0,
   0, 0, 8
  );
 
 $b = matrix
  (4, 2, 0,
   2, 4, 2,
   0, 2, 4
  );
 
 $c = matrix
  (4, 2, 1,
   2, 4, 2,
   1, 2, 4
  );
 
 $v = vector(1,2,3);
 
 ok($a/$a           == i());
 ok($b/$b           == i());
 ok($c/$c           == i());
 ok(2/$a*$a/2       == i());
 ok(($a+$b)/($a+$b) == i());
 ok(($a-$c)/($a-$c) == i());
 ok(-$a/-$a         == i());
 ok(1/$a*($a*$v)    == $v);
 

Description

3*3 matrix manipulation

Constructors

new

Create a matrix

matrix

Create a matrix = synonym for "new"

new3v

Create a matrix from three vectors

new3vnc

Create a matrix from three vectors without checking

Methods

check

Check its a matrix

is

Test its a matrix

singular

Singular matrix?

accuracy

Get/Set accuracy for comparisons

round

Round: round to nearest integer if within accuracy of that integer

clone

Create a matrix from another matrix

print

Print matrix

add

Add matrices

negate

Negate matrix

subtract

Subtract matrices

matrixVectorMultiply

Vector = Matrix * Vector

matrixScalarMultiply

Matrix = Matrix * scalar

matrixMatrixMultiply

Matrix = Matrix * Matrix

matrixScalarDivide

Matrix=Matrix / non zero scalar

det

Determinant of matrix.

d2

Determinant of 2*2 matrix

inverse

Inverse of matrix

identity

Identity matrix

equals

Equals to within accuracy

Operator

Operator overloads

Add operator

Add operator.

subtract operator

Negate operator.

multiply operator

Multiply operator.

divide operator

Divide operator.

equals operator

Equals operator.

det operator

Determinant of a matrix

Print a vector.

Exports

Export "matrix", "identity", "new3v", "new3vnc"

Credits

Author

philiprbrenan@yahoo.com

philiprbrenan@yahoo.com, 2004

License

Perl License.