Jonathan Leto > Math-MatrixReal-2.09 > Math::MatrixReal

Download:
Math-MatrixReal-2.09.tar.gz

Dependencies

Annotate this POD

Related Modules

Math::Matrix
Parse::RecDescent
PDL::Slatec
Math::BigFloat
Data::Dumper
CGI::Carp
Math::Complex
Math::Trig
Math::Pari
Inline::C
more...
By perlmonks.org

CPAN RT

New  2
Open  0
View/Report Bugs
Module Version: 2.09   Source   Latest Release: Math-MatrixReal-2.11

NAME ^

Math::MatrixReal - Matrix of Reals

Implements the data type "matrix of real numbers" (and consequently also "vector of real numbers").

SYNOPSIS ^

my $a = Math::MatrixReal->new_random(5, 5);

my $b = $a->new_random(10, 30, { symmetric=>1, bounded_by=>[-1,1] });

my $c = $b * $a ** 3;

my $d = $b->new_from_rows( [ [ 5, 3 ,4], [3, 4, 5], [ 2, 4, 1 ] ] );

print $a;

my $row = ($a * $b)->row(3);

my $col = (5*$c)->col(2);

my $transpose = ~$c;

my $transpose = $c->transpose;

my $inverse = $a->inverse;

my $inverse = 1/$a;

my $inverse = $a ** -1;

my $determinant= $a->det;

FUNCTIONS ^

Constructor Methods And Such

Matrix Row, Column and Element operations

Matrix Operations

Arithmetic Operations

Boolean Matrix Operations

Eigensystems

Miscellaneous

OVERLOADED OPERATORS ^

SYNOPSIS

DESCRIPTION

'.'

Concatenation

Returns the two matrices concatenated side by side.

Example: $c = $a . $b;

For example, if

        $a=[ 1 2 ]   $b=[ 5 6 ]         
           [ 3 4 ]      [ 7 8 ]         
then

        $c=[ 1 2 5 6 ]
           [ 3 4 7 8 ]

Note that only matrices with the same number of rows may be concatenated.

'-'

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()".

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

Examples:

    $matrix = Math::MatrixReal->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 = Math::MatrixReal->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;
'/'

Division

Currently a shortcut for doing $a * $b ** -1 is $a / $b, which works for square matrices. One can also use 1/$a .

'**'

Exponentiation

Returns the matrix raised to an integer power. If 0 is passed, the identity matrix is returned. If a negative integer is passed, it computes the inverse (if it exists) and then raised the inverse to the absolute value of the integer. The matrix must be quadratic.

Examples:

    $matrix2 = $matrix ** 2;

    $matrix **= 2;

    $inv2 = $matrix ** -2;

    $ident = $matrix ** 0;
'=='

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::VectorReal, Math::PARI, Math::MatrixBool, Math::Vec, DFA::Kleene, Math::Kleene, Set::IntegerRange, Set::IntegerFast .

VERSION ^

This man page documents Math::MatrixReal version 2.09

The latest code can be found at https://github.com/leto/math--matrixreal .

AUTHORS ^

Steffen Beyer <sb@engelschall.com>, Rodolphe Ortalo <ortalo@laas.fr>, Jonathan "Duke" Leto <jonathan@leto.net>.

Currently maintained by Jonathan "Duke" Leto, send all bugs/patches to me.

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-2011 by Steffen Beyer, Rodolphe Ortalo, Jonathan "Duke" Leto. 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.

syntax highlighting: