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

Matrix2

2*2 matrix manipulation

PhilipRBrenan@yahoo.com, 2004, Perl License

Synopsis

Example t/matrix2.t

 #_ Matrix _____________________________________________________________
 # Test 2*2 matrices    
 # philiprbrenan@yahoo.com, 2004, Perl License    
 #______________________________________________________________________
 
 use Math::Zap::Matrix2 identity=>i;
 use Math::Zap::Vector2;
 use Test::Simple tests=>8;
 
 my ($a, $b, $c, $v);
 
 $a = matrix2
  (8, 0,
   0, 8,
  );
 
 $b = matrix2
  (4, 2,
   2, 4,
  );
 
 $c = matrix2
  (2, 2,
   1, 2,
  );
 
 $v = vector2(1,2);
 
 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

2*2 matrix manipulation

Constructors

new

Create a matrix

matrix2

Create a matrix. Synonym for "new".

identity

Identity matrix

new2v

Create a matrix from two vectors

Methods

check

Check its a matrix

is

Test its a matrix

accuracy

Get/Set accuracy

round

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

singular

Singular matrix?

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.

inverse

Inverse of matrix

rotate

Rotation matrix: rotate anti-clockwise by t radians

equals

Equals to within accuracy

Operators

Operator overloads

add operator

Add operator.

subtract operator

Subtract operator.

multiply operator

Multiply operator.

divide operator

Divide operator.

equals operator

Equals operator.

determinant operator

Determinant of a matrix

Print a vector.

Exports

Export "matrix2", "identity"

Credits

Author

philiprbrenan@yahoo.com

philiprbrenan@yahoo.com, 2004

License

Perl License.