Math-MatrixSparse
view release on metacpan or search on metacpan
MatrixSparse.pm view on Meta::CPAN
C<< $matrix1->matrixor($matrix2) >>
Finds and returns the matrix whose ($i,$j) element is
$matrix1($i,$j) || $matrix2($i,$j).
The returned matrix is a pattern matrix.
=back
=head2 PROBABILISTIC METHODS
=over 4
=item *
C<< $matrix->normalize() >>
Returns a matrix $matrix2 scaled so that $matrix2->sum()==1.
Exits on error if $matrix is not nonnegative.
=item *
C<< $matrix->normalizerows() >>
As $matrix->normalize(), except that each row is scaled to have a
sum of 1.
Exits on error if $matrix is not nonnegative.
=item *
C<< $matrix->normalizecolumns() >>
As $matrix->normalizerows(), except with columns. Mathematically equivalent to
$matrix->transpose()->normalizerows()->transpose().
Exits on error if $matrix is not nonnegative.
=item *
C<< $matrix->discretepdf() >>
Assuming that $matrix->sum()==1 and $matrix is non-negative, chooses a
random element from $matrix based on the assumption that
the entry at ($i,$j) is the probability of choosing ($i,$j).
=back
=head2 SOLUTION OF SYSTEMS METHODS
=over 4
=item *
C<< $matrix->jacobi($constant,$guess, $tol, $steps) >>
Uses Jacobi iteration to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, tolerance $tol, and maximum iterations $steps.
If $steps is undefined, the default value of 100 is used.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
=item *
C<< $matrix->gaussseidel($constant,$guess, $tol, $steps) >>
Uses Gauss-Seidel iteration to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, tolerance $tol, and maximum
iterations $steps. This is equivalent to $matrix->SOR with
relaxation parameter 1.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
=item *
C<< $matrix->SOR($constant,$guess, $relax, $tol, $steps) >>
Uses Successive Over-Relaxation to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, relaxation parameter $relax, tolerance $tol, and maximum
iterations $steps.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
=back
=head2 SORTING METHODS
=over 4
=item *
C<< $matrix->sortbycolumn() >>
C<< $matrix->sortbyrow() >>
Returns an array containing the keys of $matrix, sorted primarily
by either column or row (and secondarily by row or column).
C<< $matrix->sortbydiagonal() >>
Returns an array containing the keys of $matrix, sorted primarily by
their distance from elements on the main diagonal, lower diagonals
first. The row of the key is a secondary criterion.
C<< $matrix->sortbyvalue() >>
Returns an array containing the keys of $matrix, sorted primarily by
the value of the element indexed by the key. Row and column are
secondary and tertiaty criteria.
These methods are suitable for using inside a loop. See also
$matrix->elements() if the order of the elements is not important.
Example:
A 3x3 matrix will be sorted in the following manners:
sortbycolumn()
1 4 7
2 5 8
3 6 9
sortbyrow()
1 2 3
4 5 6
7 8 9
sortbydiagonal()
4 7 9
2 5 8
1 3 6
=back
=head2 IN-LINE METHODS
The following are as described above, except that they modify their
calling object instead of a copy thereof.
( run in 1.724 second using v1.01-cache-2.11-cpan-71847e10f99 )