Polynomials (lib601.poly
)¶
Polynomials with addition, subtraction, multiplication, and roots.
-
class
lib601.poly.
Polynomial
(c)¶ Represent polynomials, and supports addition, subtraction, multiplication, and root finding.
Parameters: c – a list of numbers, starting with lowest order coefficient. Variables: order – Integer representing the order of the polynomial -
add
(other)¶ Parameters: other – the instance of Polynomial
which we want to add toself
Returns: a new instance of Polynomial
, which is the sum ofself
andother
Does not affect either input.
-
coeff
(i)¶ Returns: the coefficient associated with the \(x^{\mathtt{i}}\) term of the polynomial
-
mul
(other)¶ Parameters: other – the instance of Polynomial
which we want to multiply byself
Returns: a new instance of Polynomial
, which is the product ofself
andother
Does not affect either input.
-
roots
(start=(0.4+0.9j), epsilon=1e-12, max_iterations=1000)¶ Computes the roots of the Polynomial using the Durand-Kerner method.
Parameters: - start – (optional) seed value, defaults to \(.4+.9j\). Initial guesses for the \(k\) roots are \({\mathtt start}^0, {\mathtt start}^1, \ldots, {\mathtt start}^k\)
- epsilon – (optional) threshold, defaults to
1e-12
. The algorithm terminates (returning the roots) when one iteration changes none of the roots by more thanepsilon
. - max_iterations – (optional) the maximum number of iterations
to run, defaults to
1000
. If this number of iterations is reached and the algorithm has not converged, it will terminate and returnNone
.
Returns: A list containing the roots of the polynomial
-
sub
(other)¶ Parameters: other – the instance of Polynomial
which we want to subtract fromself
Returns: a new instance of Polynomial
, which is the difference ofself
andother
Does not affect either input.
-
val
(v)¶ Parameters: v – number Returns: the value of the polynomial when \(x\) has the value specified by the argument v
.
-