Skip to main content

Polyno: polynomial object

Project description

Polyno

Polynomial object (class)

Installation

pip install polyno

Import Poly object

from polyno import Poly

Set P1 and P2 for the examples below

Polynomial parameter is absolute list of coefficients
in descending order or dictionnary {degree:coef}
>>> P1 = Poly([3, 1, 0])
>>> P2 = Poly({0:5, 3:2})
By default, Poly.coefs is list of polynomial degrees according to reversed sorted Poly.degs.
Exemple: P2.coefs is [2, 5], not [2, 0, 0, 5]

Below, get absolute list in ascending order of coefficients
>>> P2.coefficients()
[5.0, 0, 0, 2.0]
>>> 

Print polynomial

>>> P1.toString()
'3x^2 + x'
>>> print(P1)
3x^2 + x
>>> print(P2)
2x^3 + 5
>>> 

Addition (with Poly and scalar)

>>> P1 + P2
2x^3 + 3x^2 + x + 5
>>>
>>> P1 + 2
3x^2 + x + 2
>>>

Substraction (with Poly and scalar)

>>> P1 - P2
-2x^3 + 3x^2 + x - 5
>>> P2 - P1
2x^3 - 3x^2 - x + 5
>>> P1 - 2
3x^2 + x - 2
>>>

Multiplication with scalar

>>> P1 * -2
-6x^2 - 2x
>>> P2 * 3
6x^3 + 15
>>> 

Multiplication with Poly

>>> P1 * P2
6x^5 + 2x^4 + 15x^2 + 5x
>>> 

Division with scalar

>>> P2/2
x^3 + 2.5
>>> 

Derivative

>>> P1.derivative()
6x + 1
>>> 

k_th order Derivative

>>> P2 = Poly({0:5, 3:2})
>>> print(P2.derivative())
6x^2
>>> print(P2.derivative(2))
12x
>>> print(P2.derivative(3))
12
>>>

Other method

eval: value of P(x)
integral: polynomial integral from a to b
zero: solution of P(x) = 0 for x in [a, b] interval

Futures

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyno-1.2.4.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

polyno-1.2.4-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page