NAME

Math::Assistant - functions for various exact algebraic calculations

SYNOPSIS

use Math::Assistant qw(:algebra);

my $M = [ [4,1,4,3], [3,-4,7,5], [4,-9,8,5], [-3,2,-5,3], [2,2,-1,0] ];

# Rank of rectangular matrix
my $rank = Rank($M);
print "Rank = $rank\n";

shift @{$M}; # Now a quadratic matrix

# Determinant of quadratic matrix
my $determinant = Det($M);
print "Determinant = $determinant\n";

# Solve an equation system
my $B = [ 1,2,3,4 ];
my $solve = Solve_Det($M, $B);
print "$_\n" for @{$solve};

use Math::BigRat;
print(Math::BigRat->new("$_")->numify(),"\n") for @{$solve};

will print

Rank = 4
Determinant = -558
433/279
-32/279
-314/279
70/93

1.55197132616487
-0.114695340501792
-1.12544802867384
0.752688172043011

DESCRIPTION

The module contains important algebraic operations: matrix rank, determinant and solve an equation system. The integer values are accepted. Calculations with the raised accuracy.

SUBROUTINES

Math::Assistant provides these subroutines:

Rank(\@matrix)
Det(\@matrix)
Solve_Det(\@A_matrix, \@b_vector)
Gaussian_elimination(\@matrix)

All of them are context-sensitive.

Rank(\@matrix)

Calculates rank of rectangular (quadratic or non-quadratic) @matrix. Rank is a measure of the number of linear independent row and column (or number of linear independent equations in the case of a matrix representing an equation system).

Det(\@matrix)

This subroutine returns the determinant of the @matrix. Only quadratic matrices have determinant. For non-quadratic matrix returns undef.

Solve_Det(\@A_matrix, \@b_vector)

Use this subroutine to actually solve an equation system.

Matrix "@A_matrix" must be quadratic matrix of your equation system A * x = b.

The input vector "@b_vector" is the vector "b" in your equation system A * x = b, which must be a row vector and have the same number of elements as the input matrix "@A_matrix" have rows.

The subroutine returns the solution vector "$x" (which is the vector "x" of your equation system A * x = b) or undef is no solution.

    my $M = [
	[1,1,1,1,1,1,1],
	[64,32,16,8,4,2,1],
	[729,243,81,27,9,3,1],
	[4096,1024,256,64,16,4,1],
	[5**6, 5**5, 5**4, 5**3, 5**2, 5, 1],
	[6**6, 6**5, 6**4, 6**3, 6**2, 6, 1],
	[7**6, 7**5, 7**4, 7**3, 7**2, 7, 1],
	 ];

    my $B = [ 4,85,820,4369,16276,47989,120100 ];

    my $solve = Solve_Det($M, $B);
    print "$_\t" for @{$solve};

will print: 1 0 1 0 1 0 1

    # other example
    $M = [ [1.3, 2.5, 3.1, 4.2], [2.1, 4.7, 6.2, 8.7],
	    [34, 8.2, 12, 16], [78,16,24,33] ];
    Solve_Det($M, [ 1.1, 2.2, 3.3, 4.4 ] );

will print:

-20427/173770 -47993/34754 317493/86885 -27401/17377

Gaussian_elimination(\@matrix)

This subroutine returns matrix Gaussian elimination of the @matrix. The initial @matrix does not vary.

EXPORT

Math::Assistant exports nothing by default. Each of the subroutines can be exported on demand, as in

use Math::Assistant qw( Rank );

the tag algebra exports the subroutines Rank, Det, Solve_Det:

use Math::Assistant qw(:algebra);

and the tag all exports them all:

use Math::Assistant qw(:all);

DEPENDENCIES

Math::Assistant is known to run under perl 5.8.8 on Linux. The distribution uses Algorithm::Combinatorics for the subroutine Det(), Math::BigInt and Math::BigFloat.

SEE ALSO

Math::MatrixReal is a Perl module that offers similar features.

AUTHOR

Alessandro Gorohovski, <angel@feht.dgtu.donetsk.ua>

COPYRIGHT AND LICENSE

Copyright (C) 2010 by A. N. Gorohovski

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.