MySQL操作程序十九(Math模块)

返回

NAME Math::Polynomial::Solve - Find the roots of polynomial equations. SYNOPSIS use Math::Complex; # The roots may be complex numbers. use Math::Polynomial::Solve qw(poly_roots); my @x = poly_roots(@coefficients); or use Math::Complex; # The roots may be complex numbers. use Math::Polynomial::Solve qw(poly_roots get_hessenberg set_hessenberg); # # Force the use of the matrix method. # set_hessenberg(1); my @x = poly_roots(@coefficients); or use Math::Complex; # The roots may be complex numbers. use Math::Polynomial::Solve qw(linear_roots quadratic_roots cubic_roots quartic_roots); # Find the roots of ax + b my @x1 = linear_roots($a, $b); # Find the roots of ax**2 + bx +c my @x2 = quadratic_roots($a, $b, $c); # Find the roots of ax**3 + bx**2 +cx + d my @x3 = cubic_roots($a, $b, $c, $d); # Find the roots of ax**4 + bx**3 +cx**2 + dx + e my @x4 = quartic_roots($a, $b, $c, $d, $e); DESCRIPTION This package supplies a set of functions that find the roots of polynomials. Polynomials up to the quartic may be solved directly by numerical formulae. Polynomials of fifth and higher powers will be solved by an iterative method, as there are no general solutions for fifth and higher powers. The linear, quadratic, cubic, and quartic *_roots() functions all expect to have a non-zero value for the $a term. If the constant term is zero then the first value returned in the list of answers will always be zero, for all functions. set_hessenberg() Sets or removes the condition that forces the use of the Hessenberg matrix regardless of the polynomial's degree. A non-zero argument forces the use of the matrix method, a zero removes it. get_hessenberg() Returns 1 or 0 depending upon whether the Hessenberg matrix method is always in use or not. poly_roots() A generic function that may call one of the other root-finding functions, or a polynomial solving method using a Hessenberg matrix, depending on the degree of the polynomial. You may force it to use the matrix method regardless of the degree of the polynomial by calling set_hessenberg(1). Otherwise it will use the specialized root functions for polynomials of degree 1 to 4. Unlike the other root-finding functions, it will check for coefficients of zero for the highest power, and 'step down' the degree of the polynomial to the appropriate case. Additionally, it will check for coefficients of zero for the lowest power terms, and add zeros to its root list before calling one of the root-finding functions. Thus it is possible to solve a polynomial of degree higher than 4 without using the matrix method, as long as it meets these rather specialized conditions. linear_roots() Here for completeness's sake more than anything else. Returns the solution for ax + b = 0 by returning "-b/a". This may be in either a scalar or an array context. quadratic_roots() Gives the roots of the quadratic equation ax**2 + bx + c = 0 using the well-known quadratic formula. Returns a two-element list. cubic_roots() Gives the roots of the cubic equation ax**3 + bx**2 + cx + d = 0 by the method described by R. W. D. Nickalls (see the Acknowledgments section below). Returns a three-element list. The first element will always be real. The next two values will either be both real or both complex numbers. quartic_roots() Gives the roots of the quartic equation ax**4 + bx**3 + cx**2 + dx + e = 0 using Ferrari's method (see the Acknowledgments section below). Returns a four-element list. The first two elements will be either both real or both complex. The next two elements will also be alike in type. EXPORT There are no default exports. The functions may be named in an export list. Acknowledgments The cubic The cubic is solved by the method described by R. W. D. Nickalls, "A New Approach to solving the cubic: Cardan's solution revealed," The Mathematical Gazette, 77, 354-359, 1993. This article is available on several different web sites, including <http://www.2dcurves.com/cubic/cubic.html> and <http://www.m-a.org.uk/resources/periodicals/online_articles_keyword_ind ex/>. There is also a nice discussion of his paper at <http://www.sosmath.com/algebra/factor/fac111/fac111.html>. Dr. Nickalls was kind enough to send me his article, with notes and revisions, and directed me to a Matlab script that was based on that article, written by Herman Bruyninckx, of the Dept. Mechanical Eng., Div. PMA, Katholieke Universiteit Leuven, Belgium. This function is an almost direct translation of that script, and I owe Herman Bruyninckx for creating it in the first place. Dick Nickalls, dicknickalls@compuserve.com Herman Bruyninckx, Herman.Bruyninckx@mech.kuleuven.ac.be, has web page at <http://www.mech.kuleuven.ac.be/~bruyninc>. His matlab cubic solver is at <http://people.mech.kuleuven.ac.be/~bruyninc/matlab/cubic.m>. Andy Stein has written a version of cubic.m that will work with vectors. It is included with this package in the eg directory. The quartic The method for quartic solution is Ferrari's, as described in the web page Karl's Calculus Tutor at <http://www.karlscalculus.org/quartic.html>. I also made use of some short cuts mentioned in web page Ask Dr. Math FAQ, at <http://forum.swarthmore.edu/dr.math/faq/faq.cubic.equations.html>. Quintic and higher. Back when this module could only solve polynomials of degrees 1 through 4, Matz Kindahl, the author of Math::Polynomial, suggested the poly_roots() function. Later on, Nick Ing-Simmons, who was working on a perl binding to the GNU Scientific Library, sent a perl translation of Hiroshi Murakami's Fortran implementation of the QR Hessenberg algorithm, and it fit very well into the poly_roots() function. Quintics and higher degree polynomials can now be solved, albeit through numeric analysis methods. Hiroshi Murakami's Fortran routines were at <http://netlib.bell-labs.com/netlib/>, but do not seem to be available from that source anymore. He referenced the following articles: R. S. Martin, G. Peters and J. H. Wilkinson, "The QR Algorithm for Real Hessenberg Matrices", Numer. Math. 14, 219-231(1970). B. N. Parlett and C. Reinsch, "Balancing a Matrix for Calculation of Eigenvalues and Eigenvectors", Numer. Math. 13, 293-304(1969). Alan Edelman and H. Murakami, "Polynomial Roots from Companion Matrix Eigenvalues", Math. Comp., v64,#210, pp.763-776(1995). For starting out, you may want to read Numerical Recipes in C, by William Press, Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling, Cambridge University Press. SEE ALSO Forsythe, George E., Michael A. Malcolm, and Cleve B. Moler (1977), Computer Methods for Mathematical Computations, Prentice-Hall. AUTHOR John M. Gamble may be found at jgamble@ripco.com
NAME Math::MatrixSparse - Perl extension for sparse matrices. SYNOPSIS Math::MatrixSparse is a module implementing naive sparse matrices. Its syntax is designed to partially overlap with Math::MatrixReal where possible and reasonable. Basic matrix operations are present, including addition, subtraction, scalar multiplication, matrix multiplication, transposition, and exponentiation. Three methods of solving systems iteratively are available, including Jacobi, Gauss-Seidel, and Symmetric Over-Relaxation. Real-valued matrices can be read from files in the Matrix Market and Harwell Boeing formats, and written in the Matrix Market format. In addition, they can be read from a given string. Certain special types of matrices are understood, but not optimized for, such as upper and lower triangular, diagonal, symmetric, skew-symmetric, positive, negative, and pattern. Methods are available to determine the properties of a given matrix. Individual rows, columns, and diagonals of matrices can be obtained, as can the upper and lower triangular, symmetric, skew symmetric, positive and negative portions. DESCRIPTION * "use Math::MatrixSparse;" Load the module and make its methods and operators available. CREATION AND INPUT-OUTPUT METHODS * "Math::MatrixSparse->new($name)" "new Math::MatrixSparse($name)" Creates a new empty matrix named $name, which may be undef. * "Math::MatrixSparse->newfromstring($string,$name)" Creates a new matrix named $name based on $string. $string is of the pattern /(\d+)\s+(\d+)\s+(.+)\n/, where ($row, $column, $value) = ($1,$2,$3). Example: $matrixspec = <<MATRIX; 1 1 1 1 2 2 2 1 3 3 3 4 MATRIX my $MS = Math::MatrixSparse->newfromstring($matrixspec,"MS"); $MS has four elements, (1,1), (1,2), (2,1), and (3,3), with the values 1,2,3, and 4. * "Math::MatrixSparse->newdiag($arrayref,$name)" Creates a new square matrix named $name from the elements in $arrayref. $arrayref[0] will become $matrix(1,1), etc. * " Math::MatrixSparse->newdiagfromstring($string, $name)" Similar to "Math::MatrixSparse->newfromstring" except that $string is of the pattern /(\d+)\s+(.+)\n/, and ($row, $column, $value) = ($1, $1, $2). Example: $diagspec = <<MATRIX; 1 1 2 -1 20 1 300 -1 MATRIX my $MD = Math::MatrixSparse->newdiagfromstring($matrixspec,"MS"); $MD has four elements, (1,1), (2,2), (20,20), and (300,300), with the values 1, -1, 1, and -1, and is square. * "Math::MatrixSparse->newrandom($maxrow, $maxcol, $maxentries, $density,$name)" Creates a new matrix of the specified size ($maxrow*$maxcol) with at most $maxentries. If $density is between 0 and 1 (inclusive), the expected number of entries is $maxentries*$density. If $maxentries is undef, it is set to $maxrow*$maxcol; if $maxcol is missing, it is set to $maxrow. If $density is missing, or outside the valid range, it is set to one. * "Math::MatrixSparse->newmatrixmarket($filename)" Creates a new matrix based on data stored in the file $filename, in Matrix Market format. See http://www.nist.gov/MatrixMarket/ for more information on this format. Pattern matrix data has elements set to one. Matrices flagged as symmetric or skew symmetric have symmetrify() or skewsymmetrify() applied. Exits with an error if $filename cannot be read from. * "Math::MatrixSparse->newharwellboeing($filename)" Creates a new matrix based on data stored in the file $filename, in Harwell-Boeing format. See http://math.nist.gov/MatrixMarket/collections/hb.html for more information on this format. Pattern matrix data has elements set to one. Matrices flagged as symmetric or skew symmetric have symmetrify() or skewsymmetrify() applied. Exits with an error if $filename cannot be read from. * "$matrix->writematrixmarket($filename)" The contents of $matrix are written, in Matrix Market format, to $filename. It is assumed that $matrix->{rows} and $matrix->{columns} are accurate--$matrix->sizetofit() should be called if this is not the case. No optimizations are performed for symmetric, skew symmetric, or pattern data, and real values are assumed. See http://www.nist.gov/MatrixMarket/ for more information on this format. Exits with an error if $filename cannot be written to. * "Math::MatrixSparse->newidentity($n,$m)" Creates an identity matrix with $n rows and $m columns. If $m is omitted it is assumed equal to $n. * "print $matrix" "$matrix->print($name)" "$matrix->print()" Prints the element in the matrix in the format $name($row,$colum) = $value Calling this as a method with an argument overrides the value in $matrix->{name}. INTERFACE METHODS * "($i,$j) = &splitkey($key)" "$key = &makekey($i,$j)" These two routines convert a position ($i,$j) of the matrix into a key $key. Programs that use Math::MatrixSparse should not have to use keys at all, but if they do, they should use these routines. GENERAL METHODS * "$matrix2 = $matrix1->copy()" "$matrix2 = $matrix1->copy($name)" Returns an exact copy of $matrix1, including dimensions, name, and special flags. If $name is given, it will be the name of $matrix2. * "$matrix->name($name)" Gives a name to $matrix. Useful mostly in printing. Certain methods attempt to create useful names, but you probably want to set your own. * "$matrix->assign($i,$j,$value)" Puts $value in row $i, column $j of $matrix. Updates $matrix->{row} and $matrix->{column} if necessary. Removes or modifies special flags when necessary. * "$matrix->assignspecial($i,$j,$value)" As $matrix->assign(), except that it preserves symmetry and skew-symmetry. That is, if $matrix is marked symmetric, assigning a value to ($i,$j) also assigns the value to ($j,$i). Also preserves patterns. * "$matrix->assignkey($key,$value)" As $matrix->assign(), except $i and $j have already been combined into $key. * "$matrix->element($i,$j)" Returns the element at row $i column $j of $matrix. * "$matrix->elementkey($key)" As $matrix->element(), except $i and $j have already been combined into $key. * "$matrix->elements()" Returns an array consisting of all the elements of $matrix, in key form, suitable for a loop. See also SORTING METHODS below if the order of the elements is important. Example: foreach my $key ($matrix->elements()) { my ($i,$j) = &splitkey($key); ... } * "$matrix->delete($i,$j)" Deletes the ($i,$j) element of $matrix. * "$matrix->deletekey($key)" As $matrix->delete(), except $i and $j have already been combined into $key. * "$matrix->cull()" Returns a copy of $matrix with any zero elements removed. Equivalent to $matrix->threshold(0). * "$matrix->threshold($thresh)" Returns a copy of $matrix with any elements with absolute value less than $thresh removed. * "$matrix->sizetofit()" Returns a copy of $matrix with dimensions sufficient only to cover its data. * "$matrix->clearspecials()" Removes all knowledge of special properties of $matrix. Use $matrix->diagnose() to put them back. DECOMPOSITIONAL METHODS * "$matrix->row($i)" "$matrix->row($i,$persist)" Returns a matrix consisting only of the $i th row of $matrix. If $persist is non-zero, the elements of $matrix are sorted by row, to speed up future calls to row(). Note that many methods, most notably assign() and delete(), remove the data necessary to use the fast algorithm. If this data is present, a binary search is used instead of an exhaustive term-by-term search. There is an intial cost of O(n log n) operations (n==$matrix->count()) to use this data, but each search costs O(log n) operations. This is in comparison to O(n) operations without the data. So, in summary, if many separate rows are needed, and the matrix is unchanging, the first (at least) call to row() should have a non-zero value of $persist. * "$matrix->column($j)" "$matrix->column($j,$persist)" Returns a matrix consisting only of the $j th column of $matrix. See also $matrix->row(). * "$matrix->diagpart($offset)" If $offset is zero or undefined, returns a matrix consisting of the diagonal elements of $matrix, if any. If $offset is non-zero, returns a parallel diagonal. For example, if $offset=1, the first superdiagonal is returned. Posive $offset s return diagonals above the main diagonal, negative offsets return diagonals below the main diagonal. The returned matrix is the same size as $matrix. * "$matrix->lowerpart()" Returns a matrix consisting of the strictly lower triangular parts of $matrix, if any. The returned matrix is the same size as $matrix. * "$matrix->upperpart()" Returns a matrix consisting of the strictly upper triangular parts of $matrix, if any. The returned matrix is the same size as $matrix. * "$matrix->nondiagpart($offset)" "$matrix->nonlowerpart()" "$matrix->nonupperpart()" As before, except that the returned matrix is everything except the part specified. Example: A = D1 U1 U2 L1 D2 U3 L2 L3 D3 $A->lowerpart() == L1 L2 L3 $A->diagpart() == D1 D2 D3 $A->diagpart(1) == U1 U3 $A->diagpart(-1) == L1 L3 $A->upperpart() == U1 U2 U3 $A->nonlowerpart() == D1 U1 U2 D2 U3 D3 $A->nondiagpart(1) == D1 U2 L1 D2 L2 L3 D3 * "$matrix->symmetricpart()" Returns the symmetric part of $matrix, i.e. 0.5*($matrix+$matrix->transpose()). * "$matrix->skewsymmetricpart()" Returns the skewsymmetric part of $matrix, i.e. 0.5*($matrix-$matrix->transpose()). * "$matrix->positivepart()" Returns the positive part of $matrix, i.e. those elements of $matrix larger than zero. * "$matrix->negativepart()" Returns the positive part of $matrix, i.e. those elements of $matrix larger than zero. * "$matrix->mask($i1,$i2,$j1,$j2)" Returns a matrix whose only elements are inside ($i1,$j1) ($i1,$j2) ($i2,$j1) ($i2,$j2) * "$matrix->submatrix($i1,$i2,$j1,$j2)" Returns that portion of $matrix between ($i1,$j1) ($i1,$j2) ($i2,$j1) ($i2,$j2) Subscripts are changed, so $matrix($i1,$j1) is $submatrix(1,1). * "$matrix1->insert($i,$j,$matrix2)" The values of $matrix2 are assigned to the values of $matrix1, offset by ($i,$j). That is, $matrix1($i+$k,$j+$l)=$matrix2($j,$l). * "$A = $matrix->shift($row,$col)" Creates a new matrix $A, $matrix($i,$j) == $A($i+$row,$j+$col) INFORMATIONAL METHODS * "$matrix->dim()" Returns ($matrix->{rows}, $matrix->{columns}) * "$matrix->exactdim()" Calculates explicitly the dimension of $matrix. This differs from $matrix->dim() in that $matrix->{rows} and $matrix->{columns} may not have been updated properly. * " $matrix->count()" Returns the number of defined elements in $matrix, 0 or otherwise. * "$matrix->width()" Calculates the bandwidth of $matrix, i.e. the maximum value of abs($i-$j) for all elements at ($i,$j) in $matrix. * "$matrix->sum()" Finds the sum of all elements in $matrix. * "$matrix->abssum()" Finds the sum of the absolute values of all elements in $matrix. * "$matrix->sumeach($coderef)" Applies &$coderef to each of the elements of $matrix, and sums the result. See "$matrix->each($coderef)" for more details. * "$matrix->columnnorm()" "$matrix->norm_one()" Finds the maximum column sum of $matrix. That is, for each column of $matrix, find the sum of absolute values of its elements, then return the largest such sum. "norm_one" is provided for compatibility with Math::MatrixReal. * "$matrix->rownorm()" "$matrix->norm_max()" Finds the maximum row sum of $matrix. That is, for each row of $matrix, find the sum of absolute values of its elements, then return the largest such sum. "norm_max" is provided for compatibility with Math::MatrixReal. * "$matrix->norm_frobenius()" Finds the Frobenius norm of $matrix. This is just an alias of sqrt($matrix->sumeach(sub {$_[0]*$_[0]}). * "$matrix->trace()" Finds the trace of $matrix, which is the sum of its diagonal elements. This just is an alias for $matrix->diagpart->sum(). * "$matrix->diagnose()" Sets the special flags of $matrix. BOOLEAN INFORMATIONAL METHODS The following is_xxx() methods use the special flags if they are present. If more than one will be called for a given matrix, consider calling $matrix->diagnose() to set the flags. * "$matrix->is_square()" "$matrix->is_quadratic()" Returns the value of the comparison $matrix->{rows}==$matrix->{columns} That is, it returns 1 if the matrix is square, 0 otherwise. * "$matrix->is_diagonal()" Returns 1 if $matrix is a diagonal matrix, 0 otherwise. $matrix need not be square. * "$matrix->is_lowertriangular()" Returns 1 if $matrix is a lower triangular matrix, 0 otherwise. $matrix need not be square. Diagonal elements are allowed. * "$matrix->is_strictlowertriangular()" Returns 1 if $matrix is a lower triangular matrix, 0 otherwise. $matrix need not be square. Diagonal elements are not allowed. * "$matrix->is_uppertriangular()" Returns 1 if $matrix is an upper triangular matrix, 0 otherwise. $matrix need not be square. Diagonal elements are allowed. * "$matrix->is_strictuppertriangular()" Returns 1 if $matrix is an upper triangular matrix, 0 otherwise. $matrix need not be square. Diagonal elements are not allowed. * "$matrix->is_positive()" Returns 1 if all elements of $matrix are positive, 0 otherwise. * "$matrix->is_negative()" Returns 1 if all elements of $matrix are negative, 0 otherwise. * "$matrix->is_nonpositive()" Returns 1 if all elements of $matrix are nonpositive (i.e. <=0), 0 otherwise. * "$matrix->is_nonnegative()" Returns 1 if all elements of $matrix are nonnegative (i.e. >=0), 0 otherwise. * "$matrix->is_boolean()" "$matrix->is_pattern()" Returns 1 if all elements of $matrix are 0 or 1, 0 otherwise. * "$matrix->is_symmetric()" Returns 1 if $matrix is symmetric, i.e. $matrix==$matrix->transpose(), 0 otherwise. $matrix is assumed to be square. * "$matrix->is_skewsymmetric()" Returns 1 if $matrix is skew-symmetric, i.e. $matrix==-1*$matrix->transpose(), 0 otherwise. $matrix is assumed to be square. ARITHMETIC METHODS * "$matrix1->add($matrix2)" Finds and returns $matrix1 + $matrix2. Matrices must be of the same size. * "$matrix1->multiply($matrix2)" Finds and returns $matrix1 * $matrix2. $matrix1->{columns} must equal $matrix2->{rows}. * "$matrix1->multiplyfree($matrix2)" "$matrix1->addfree($matrix2)" As add() and multiply(), but with no limitations on the dimensions of the matrices. * "$matrix1->quickmultiply($matrix2)" "$matrix1->quickmultiplyfree($matrix2)" As multiply() and multiplyfree(), but with a different algorithm that is faster for larger matrices. * "$matrix->multiplyscalar($scalar)" Returns the product of $matrix and $scalar. * "$matrix1->kronecker($matrix2)" Returns the direct product of $matrix1 and $matrix2. Every element of $matrix1 is multiplied by the entirely of $matrix2, and those matrices assembled into a big matrix and returned. * "$matrix->exponentiate($n)" "$matrix->largeexponentiate($n)" Finds and returns $matrix raised to the $n th power. $n must be nonnegative and integral, and $matrix must be square. For large values of $n, largeexponentiate() is faster. * "$matrix->terminvert()" Returns the matrix whose elements are the multiplicative inverses of $matrix. If $matrix is square diagonal, "$matrix->terminvert()" is the multiplicative inverse of $matrix. * "$matrix->transpose()" Returns the transpose of $matrix. * "$matrix->each($coderef)" Applies a subroutine referred to by $coderef to each element of $matrix. &$coderef should take three arguments ($value, $row, $column). * "$matrix->symmetrify()" Returns a matrix obtained by reflecting $matrix about its main diagonal. $matrix does not need to be square. Exits with an error if $matrix(i,j) and $matrix(j,i) both exist and are not identical. * "$matrix->skewsymmetrify()" As symmetrify(), except that the reflected terms are made negative. Exits with an error if $matrix(i,j) and $matrix(j,i) both exist and are not negatives of each other. * "$matrix1->matrixand($matrix2)" Finds and returns the matrix whose ($i,$j) element is $matrix1($i,$j) && $matrix2($i,$j). The returned matrix is a pattern matrix. * "$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. PROBABILISTIC METHODS * "$matrix->normalize()" Returns a matrix $matrix2 scaled so that $matrix2->sum()==1. Exits on error if $matrix is not nonnegative. * "$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. * "$matrix->normalizecolumns()" As $matrix->normalizerows(), except with columns. Mathematically equivalent to $matrix->transpose()->normalizerows()->transpose(). Exits on error if $matrix is not nonnegative. * "$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). SOLUTION OF SYSTEMS METHODS * "$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. * "$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. * "$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. SORTING METHODS * "$matrix->sortbycolumn()" "$matrix->sortbyrow()" Returns an array containing the keys of $matrix, sorted primarily by either column or row (and secondarily by row or column). "$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. "$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 IN-LINE METHODS The following are as described above, except that they modify their calling object instead of a copy thereof. "_each" "_mask" "_insert" "_cull" "_threshold" "_sizetofit" "_negate" "_multiplyscalar" "_terminvert" "_symmetrify" "_skewsymmetrify" "_normalize()" "_normalizerows()" "_normalizecolumns()" "_diagpart()" "_nondiagpart()" "_upperpart()" "_nonupperpart()" "_lowerpart()" "_nonlowerpart()" "_positivepart()" "_negativepart()" "_symmetricpart()" "_skewsymmetricpart()" In addition to these, the following methods modify the calling object. "name()" "assign()" "assignspecial()" "assignkey()" "row()" (if called with the optional second argument) "column()" (if called with the optional second argument) "diagnose()" "delete()" "deletekey()" "clearspecials()" OVERLOADED OPERATORS "+" add() "-" subtract() "*" quickmultiply() "x" kronecker() "**" exponential() "~" transpose() "&" matrixand() "|" matrixor() "" print() Unary "-" negate() SPECIAL MATRIX FLAGS Certain information is stored about the matrix, and is updated when necessary. See also "$matrix->diagnose()". All flags can also be "undef". These should not be accessed directly--use the boolean is_whatever() methods instead. *structure* The symmetry of the matrix. Can be "symmetric" or "skewsymmetric". *shape* The shape of the matrix. Can be "diagonal", "lower" (triangular), "upper", "strictlower" or "strictupper". *sign* The sign of all the elemetns of a matrix. Can be "positive", "negative", "nonpostive", "nonnegative", or "zero". *pattern* Indicates whether the matrix should be treated as a pattern. Is non-zero if so. *bandwidth* Calculates the bandwidth of $matrix, i.e. the maximum value of abs($i-$j) for all elements at ($i,$j) in $matrix. *field* The underlying field of the elements of the matrix. Currently, can only be "real". INTERFACING The user should not attempt to access the pieces of a Math::MatrixReal object directly, but instead use the routines provided. Certain methods, such as the sorters, return keys to the elements of the matrix, and these should be fed into "splitkey()" to obtain row-column indices. EXPORT None. EXPORT_OK &splitkey() and &makekey(). BUGS Horribly, hideously inefficient. No checks are made to be sure that values are of a proper type, or even that indices are integers. It is entirely possible to assign() a value that is, say, another Math::MatrixSparse. However, because of the lack of these checks, indices can start at zero, or even negative values, if an algorithm calls for it. Harwell Boeing support is not robust, and output is not implemented. Complex matrices in Harwell Boeing and Matrix Market are not supported. In Matrix Market format, only the real part is read--the imaginary part is discarded. Many methods do not modify their calling object, but instead return a new object. This can be inefficent and a waste of resources, especially when it will be assigned to the new object anyway. Use the analogous methods listed in IN-LINE METHODS instead if this is an issue. AUTHOR Jacob C. Kesinger, <kesinger@math.ttu.edu> SEE ALSO perl, Math::MatrixReal.
NAME Math::GMatrix - Extension of Math::Matrix for (2D graphics-)vector manipulation SYNOPSIS use Math::GMatrix; DESCRIPTION The following methods are available: new Constructor arguments are a list of references to arrays of the same length. The arrays are copied. The method returns undef in case of error. $a = new Math::Matrix ([rand,rand,rand], [rand,rand,rand], [rand,rand,rand]); As s special case you can pass a single argument 'I' for getting an identity matrix. If you call "new" as method, a zero filled matrix with identical deminsions is returned. xform You can transform one or more vectors by calling: @V1=(1.5,3.7); @V2 = $M->xform(@V1); @L1=( [1.5,3.7], [4.6,6.8], [5.1,-0.7] ); @L2 = $M->xform(@L1); translate You can pan (move by x and y offset) your graphics by calling: $M2 = $M->translate(2.5,10.2); rotate You can rotate your graphics by calling: $M2 = $M->rotate(-90); scale You can scale (factor_x and factor_y) your graphics by calling: $M2 = $M->rotate(2,2); EXAMPLE @ListOfVectors = [ [0,1], [3,5], [2,7], [8,-1], ]; $paperwidth = 21; # DIN A4 is 21x29.7 cm $M = new Math::Matrix('I'); # get an identity matrix $M = $M->translate(-1,-1)->rotate(90)->translate($paperwidth-1,1); @Result = $M->xform(@ListOfVectors); AUTHOR A. Cester, <albert.cester@web.de>
返回