maths.polynomials.single_indeterminate_operations

This module implements a single indeterminate polynomials class with some basic operations

Reference: https://en.wikipedia.org/wiki/Polynomial

Classes

Polynomial

Module Contents

class maths.polynomials.single_indeterminate_operations.Polynomial(degree: int, coefficients: collections.abc.MutableSequence[float])
__add__(polynomial_2: Polynomial) Polynomial

Polynomial addition >>> p = Polynomial(2, [1, 2, 3]) >>> q = Polynomial(2, [1, 2, 3]) >>> p + q 6x^2 + 4x + 2

__eq__(polynomial_2: object) bool

Checks if two polynomials are equal. >>> p = Polynomial(2, [1, 2, 3]) >>> q = Polynomial(2, [1, 2, 3]) >>> p == q True

__mul__(polynomial_2: Polynomial) Polynomial

Polynomial multiplication >>> p = Polynomial(2, [1, 2, 3]) >>> q = Polynomial(2, [1, 2, 3]) >>> p * q 9x^4 + 12x^3 + 10x^2 + 4x + 1

__ne__(polynomial_2: object) bool

Checks if two polynomials are not equal. >>> p = Polynomial(2, [1, 2, 3]) >>> q = Polynomial(2, [1, 2, 3]) >>> p != q False

__neg__() Polynomial

Polynomial negation >>> p = Polynomial(2, [1, 2, 3]) >>> -p

  • 3x^2 - 2x - 1

__repr__() str
>>> p = Polynomial(2, [1, 2, 3])
>>> p
3x^2 + 2x + 1
__str__() str
>>> p = Polynomial(2, [1, 2, 3])
>>> print(p)
3x^2 + 2x + 1
__sub__(polynomial_2: Polynomial) Polynomial

Polynomial subtraction >>> p = Polynomial(2, [1, 2, 4]) >>> q = Polynomial(2, [1, 2, 3]) >>> p - q 1x^2

derivative() Polynomial

Returns the derivative of the polynomial. >>> p = Polynomial(2, [1, 2, 3]) >>> p.derivative() 6x + 2

evaluate(substitution: float) float

Evaluates the polynomial at x. >>> p = Polynomial(2, [1, 2, 3]) >>> p.evaluate(2) 17

integral(constant: float = 0) Polynomial

Returns the integral of the polynomial. >>> p = Polynomial(2, [1, 2, 3]) >>> p.integral() 1.0x^3 + 1.0x^2 + 1.0x

coefficients: list[float]
degree