Skip to main content

provides mathematical Polynomials as Python objects

Project description

pynomials

This is a simple Mathematical Module which is extremely user-friendly. The module deals with mathematical Polynomials in one variable, namely "x". Using this module, the algebra of Polynomials can be easily performed in python.
Polynomial(an, ..., a2, a1, a0) -> anx^n + ... + a2x^2 + a1x^1 + a0x^0
A lot of help text is included in the class, and in the error messages, hence making the module easy to use.

Attributes of Polynomial objects

Polynomials have the following attributes:

  • self.degree = highest power of x
  • self.coeffs = (an, ..., a2, a1, a0)
  • self.a0, self.a1, self.a2, ... = a0, a1, a2, ...

Note: degree of Zero Polynomial is None as it is left exclusively undefined in Mathematics

Methods

  • add two Polynomials:

    returns the Polynomial obtained by adding the Polynomials
    can be achieved through p1 + p2

  • subtract two Polynomials:

    returns the Polynomial obtained by subtracting the Polynomials
    can be achieved through p1 - p2

  • multiply two Polynomials:

    returns the Polynomial obtained by multiplying the Polynomials
    can be achieved through p1 * p2

  • divide two Polynomials (/, //, %):

    / : returns the Rational Function obtained by p1 / p2 as a python function
    //: returns the Quotient obtained by p1 // p2 if the result is a Polynomial else None
    % : returns the Remainder obtained by p1 % p2 if the result of p1 // p2 is a Polynomial else None

  • raise Polynomials to integer powers:

    returns the Polynomial obtained by raising a Polynomial to an integer power
    can be obtained through p ** n

  • indexing a Polynomial:

    p[n] -> returns the coefficient of x^n (i.e. coefficient at degree n)

  • accessing Polynomial as a function:

    p1(n) -> returns the value of the Polynomial function at x = n
    p1(p2) -> returns the Polynomial obtained by composition defined as P(Q(x)) where P, Q = p1, p2

  • Polynomial.derivative(p)

    returns the Polynomial obtained by differentiating p

  • Polynomial.integral(p, c=0)

    returns the Polynomial obtained by integrating p at value of integrating constant c

Alternate Polynomial constructors:

  • Polynomial.FromRoots(root1, root2, ..., rootn)

    creates a Polynomial of degree n whose roots are given as arguments, where n is the number of roots

  • Polynomial.FromSequence(seq)

    creates a Polynomial whose components are taken from the given list, tuple or generator
    the elements of the sequence are passed to the Polynomial() constructor in order

And many more... Each function contains help text that can be accessed through help() in python to know more about it. Users are advised to read help() on methods they want to use to ensure required results.

Plotting a Polynomial

Two methods allow you to plot the Polynomial on a graph:

  • Polynomial.plot(p1, limits=(-100, 100)):

    plots single Polynomial

  • Polynomial.plot_polynomials(p1, p2, p3, ..., pn, limits=(-100, 100), show_legend=True):

    plots multiple Polynomials on the same grid
    show_legend is a boolean which displays legend on the plot if True

Note: limits should be a tuple containing the minimum and maximum values for x

Reach out to me

Feel free to reach out to me if you notice any bugs or if you need any kind of help from me in understanding the usage of the module or the source code. My email: knightt1821@gmail.com

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

pynomials-0.0.3.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

pynomials-0.0.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file pynomials-0.0.3.tar.gz.

File metadata

  • Download URL: pynomials-0.0.3.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pynomials-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1acff9c07fe5579134842872917357376422b435312ce1459c351151cc678ce9
MD5 084096f726ced9e588a522a306db884a
BLAKE2b-256 b4c39a2ce42cabf19a0fc1922dcca0f5b214d3fffceadeb0bbc31cd242581567

See more details on using hashes here.

File details

Details for the file pynomials-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pynomials-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pynomials-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dea82fce26658e1dd5343f8a0a9a42213c6a55742e8a7be5815ae42f39a0747a
MD5 805d68e7a9cede72bf43ea600ef31878
BLAKE2b-256 deb94cdab53c96ebde20f35dba54d37da24f30157040b841769bdceba54f8349

See more details on using hashes here.

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