NAME

MatrixReal1 - Matrix of Reals

Implements the data type "matrix of reals" (and consequently also "vector of reals")

DESCRIPTION

Implements the data type "matrix of reals", which can be used almost like any other basic Perl type thanks to OPERATOR OVERLOADING, i.e.,

$product = $matrix1 * $matrix2;

does what you would like it to do (a matrix multiplication).

Also features many important operations and methods: matrix norm, matrix transposition, matrix inverse, determinant of a matrix, order and numerical condition of a matrix, scalar product of vectors, vector product of vectors, vector length, projection of row and column vectors, a comfortable way for reading in a matrix from a file, the keyboard or your code, and many more.

Allows to solve linear equation systems using an efficient algorithm known as "L-R-decomposition" and several approximative (iterative) methods.

Features an implementation of Kleene's algorithm to compute the minimal costs for all paths in a graph with weighted edges (the "weights" being the costs associated with each edge).

SYNOPSIS

Eigensystems

OVERLOADED OPERATORS

SYNOPSIS

DESCRIPTION

'-'

Unary minus

Returns the negative of the given matrix, i.e., the matrix with all elements multiplied with the factor "-1".

Example:

$matrix = -$matrix;
'~'

Transposition

Returns the transposed of the given matrix.

Examples:

$temp = ~$vector * $vector;
$length = sqrt( $temp->element(1,1) );

if (~$matrix == $matrix) { # matrix is symmetric ... }
abs

Norm

Returns the "one"-Norm of the given matrix.

Example:

$error = abs( $A * $x - $b );
test

Boolean test

Tests wether there is at least one non-zero element in the matrix.

Example:

if ($xn_vector) { # result of iteration is not zero ... }
'!'

Negated boolean test

Tests wether the matrix contains only zero's.

Examples:

if (! $b_vector) { # heterogenous equation system ... }
else             { # homogenous equation system ... }

unless ($x_vector) { # not the null-vector! }
'""""'

"Stringify" operator

Converts the given matrix into a string.

Uses scientific representation to keep precision loss to a minimum in case you want to read this string back in again later with "new_from_string()".

Uses a 13-digit mantissa and a 20-character field for each element so that lines will wrap nicely on an 80-column screen.

Examples:

$matrix = MatrixReal1->new_from_string(<<"MATRIX");
[ 1  0 ]
[ 0 -1 ]
MATRIX
print "$matrix";

[  1.000000000000E+00  0.000000000000E+00 ]
[  0.000000000000E+00 -1.000000000000E+00 ]

$string = "$matrix";
$test = MatrixReal1->new_from_string($string);
if ($test == $matrix) { print ":-)\n"; } else { print ":-(\n"; }
'+'

Addition

Returns the sum of the two given matrices.

Examples:

$matrix_S = $matrix_A + $matrix_B;

$matrix_A += $matrix_B;
'-'

Subtraction

Returns the difference of the two given matrices.

Examples:

$matrix_D = $matrix_A - $matrix_B;

$matrix_A -= $matrix_B;

Note that this is the same as:

$matrix_S = $matrix_A + -$matrix_B;

$matrix_A += -$matrix_B;

(The latter are less efficient, though)

'*'

Multiplication

Returns the matrix product of the two given matrices or the product of the given matrix and scalar factor.

Examples:

$matrix_P = $matrix_A * $matrix_B;

$matrix_A *= $matrix_B;

$vector_b = $matrix_A * $vector_x;

$matrix_B = -1 * $matrix_A;

$matrix_B = $matrix_A * -1;

$matrix_A *= -1;
'=='

Equality

Tests two matrices for equality.

Example:

if ( $A * $x == $b ) { print "EUREKA!\n"; }

Note that in most cases, due to numerical errors (due to the finite precision of computer arithmetics), it is a bad idea to compare two matrices or vectors this way.

Better use the norm of the difference of the two matrices you want to compare and compare that norm with a small number, like this:

if ( abs( $A * $x - $b ) < 1E-12 ) { print "BINGO!\n"; }
'!='

Inequality

Tests two matrices for inequality.

Example:

while ($x0_vector != $xn_vector) { # proceed with iteration ... }

(Stops when the iteration becomes stationary)

Note that (just like with the '==' operator), it is usually a bad idea to compare matrices or vectors this way. Compare the norm of the difference of the two matrices with a small number instead.

'<'

Less than

Examples:

if ( $matrix1 < $matrix2 ) { # ... }

if ( $vector < $epsilon ) { # ... }

if ( 1E-12 < $vector ) { # ... }

if ( $A * $x - $b < 1E-12 ) { # ... }

These are just shortcuts for saying:

if ( abs($matrix1) < abs($matrix2) ) { # ... }

if ( abs($vector) < abs($epsilon) ) { # ... }

if ( abs(1E-12) < abs($vector) ) { # ... }

if ( abs( $A * $x - $b ) < abs(1E-12) ) { # ... }

Uses the "one"-norm for matrices and Perl's built-in "abs()" for scalars.

'<='

Less than or equal

As with the '<' operator, this is just a shortcut for the same expression with "abs()" around all arguments.

Example:

if ( $A * $x - $b <= 1E-12 ) { # ... }

which in fact is the same as:

if ( abs( $A * $x - $b ) <= abs(1E-12) ) { # ... }

Uses the "one"-norm for matrices and Perl's built-in "abs()" for scalars.

'>'

Greater than

As with the '<' and '<=' operator, this

if ( $xn - $x0 > 1E-12 ) { # ... }

is just a shortcut for:

if ( abs( $xn - $x0 ) > abs(1E-12) ) { # ... }

Uses the "one"-norm for matrices and Perl's built-in "abs()" for scalars.

'>='

Greater than or equal

As with the '<', '<=' and '>' operator, the following

if ( $LR >= $A ) { # ... }

is simply a shortcut for:

if ( abs($LR) >= abs($A) ) { # ... }

Uses the "one"-norm for matrices and Perl's built-in "abs()" for scalars.

SEE ALSO

Math::MatrixBool(3), DFA::Kleene(3), Math::Kleene(3), Set::IntegerRange(3), Set::IntegerFast(3).

VERSION

This man page documents MatrixReal1 version 1.3.

AUTHORS

Steffen Beyer <sb@sdm.de>, Rodolphe Ortalo <ortalo@laas.fr>.

CREDITS

Many thanks to Prof. Pahlings for stoking the fire of my enthusiasm for Algebra and Linear Algebra at the university (RWTH Aachen, Germany), and to Prof. Esser and his assistant, Mr. Jarausch, for their fascinating lectures in Numerical Analysis!

COPYRIGHT

Copyright (c) 1996, 1997, 1999 by Steffen Beyer and Rodolphe Ortalo. All rights reserved.

LICENSE AGREEMENT

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.