Math::Polynomial

Perl class for polynomials in one variable
Download

Math::Polynomial Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Martin Becker
  • Publisher web site:
  • http://search.cpan.org/~mhasch/

Math::Polynomial Tags


Math::Polynomial Description

Perl class for polynomials in one variable Math::Polynomial is a Perl module that represent polynomials in one variable, i.e. expressions built with finitely many additions, subtractions and multiplications of the variable and some constants. A standard way of writing down a polynomial in one variable is as a sum of products of some constant and a power of x, ordered by powers of x. The constants in those terms are called coefficients.The polynomial p(x) = 0 is called the zero polynomial. For polynomials other than the zero polynomial, the exponent of the highest power of x with a nonzero coefficient is called the degree of the polynomial.New Math::Polynomial objects can be created using a variety of constructors, or as results of expressions composed from existing objects. Math::Polynomial objects are immutable with respect to mathematical properties; all operations on polynomials create and return new objects rather than modifying anything.The module works with various types of coefficients, like ordinary floating point numbers, complex numbers, arbitrary precision rationals, matrices, elements of finite fields, and lots of others. All that is required is that the coefficients are either Perl numbers or objects with suitably overloaded arithmetic operators. Operations on polynomials are carried out by reducing them to basic operations in the domain of their coefficients.Math::Polynomial objects are implicitly bound to their coefficient space, which will be inherited when new polynomials are derived from existing ones, or determined from actual coefficients when polynomials are created from scratch. It is the responsibility of the application not to mix coefficients that cannot be added to or multiplied by each other.Note that ordinary Perl numbers used as coefficients have the disadvantage that rounding errors may lead to undesired effects, such as unexpectedly non-zero division remainders or failing equality checks.SYNOPSIS use Math::Polynomial 1.000; $p = Math::Polynomial->new(0, -2, 0, 1); # x^3 - 2 x print "p = $p "; # p = (x^3 + -2 x) $p->string_config({ fold_sign => 1 }); print "p = $p "; # p = (x^3 - 2 x) $q = $p->new(0, 3, 0, -4, 0, 1); # x^5 - 4 x^3 + 3 x $r = $p ** 2 - $p * $q; # arithmetic expression $bool = $p == $q; # boolean expression ($s, $t) = $r->divmod($q); # q * s + t = r $u = $r->gcd($q); # greatest common divisor, # here: u = 3 x $v = $u->monize; # v = x $y = $p->evaluate(0.5); # y = p(0.5) = -0.875 $d = $q->degree; # d = degree(q) = 5 $w = $p->interpolate(, ); # w(0) = -1, w(1) = 0, # w(2) = 3 use Math::Complex; $p = Math::Polynomial->new(i, 1+i); # p(x) = (1+i)*x + i Requirements: · Perl


Math::Polynomial Related Software