Module poly :: Class Polynomial
[frames] | no frames]

Class Polynomial

Represent polynomials, and supports addition, subtraction, and root finding.

Instance Methods
 
__init__(self, coeffs)
 
coeff(self, i)
 
add(p1, p2)
Returns: a new polynomial, which is their sum.
 
__add__(p1, p2)
 
__sub__(p1, p2)
 
scalarMult(self, s)
Returns: a new polynomial with all coefficients of self, multiplied by s
 
mul(p1, p2)
Returns: a new polynomial, which is their product.
 
shift(p, a)
Returns: a new polynomial, multiplied by x**a.
 
__mul__(p1, p2)
 
__str__(self, var='z')
 
__repr__(self, var='z')
 
val(self, x)
Returns: the value of the polynomial with the variable assigned to x.
 
__call__(self, x)
 
roots(self)
Returns: list of the roots, found by numpy
Instance Variables
  coeffs
List of coefficients of the polynomial, highest order first
  order
Order of the polynomial; one less than the number of coeffs
Method Details

__init__(self, coeffs)
(Constructor)

 
Parameters:
  • coeffs - a list of numbers, starting with highest order coefficient.

add(p1, p2)

 
Parameters:
  • p1, p2 - polynomials
Returns:
a new polynomial, which is their sum. Does not affect either input.

scalarMult(self, s)

 
Parameters:
  • s - a scalar
Returns:
a new polynomial with all coefficients of self, multiplied by s

mul(p1, p2)

 
Parameters:
  • p1, p2 - polynomials
Returns:
a new polynomial, which is their product.

Does not affect either input.

shift(p, a)

 
Parameters:
  • a - integer
Returns:
a new polynomial, multiplied by x**a.

Just adds zeros for new low-order coefficients.

val(self, x)

 
Parameters:
  • x - number
Returns:
the value of the polynomial with the variable assigned to x.

roots(self)

 
Returns:
list of the roots, found by numpy