Feat: Init polynomial with coefficients
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bertrand Benjamin 2021-02-04 10:18:12 +01:00
parent ff4d8471ef
commit cbcead48f7
4 changed files with 19 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
from .calculus import Expression, Integer, Decimal, random_list, render from .calculus import Expression, Integer, Decimal, random_list, render, Polynomial
# Expression.set_render('tex') # Expression.set_render('tex')

View File

@ -125,6 +125,7 @@ x^7
from .expression import Expression from .expression import Expression
from .tokens import Token from .tokens import Token
from .tokens.polynomial import Polynomial
from .tokens.number import Integer, Decimal, Fraction from .tokens.number import Integer, Decimal, Fraction
from .renders import render from .renders import render

View File

@ -15,6 +15,7 @@ from .token import Token
from . import to_be_token from . import to_be_token
from ...core.MO import MO from ...core.MO import MO
from ...core.MO.atoms import moify from ...core.MO.atoms import moify
from ...core.MO.polynomial import MOpolynomial
__all__ = ["Polynomial", "Quadratic", "Linear"] __all__ = ["Polynomial", "Quadratic", "Linear"]
@ -44,9 +45,21 @@ class Polynomial(Token):
return cls(mo, name, ancestor) return cls(mo, name, ancestor)
@classmethod @classmethod
def from_coefficients(cls, coefficients): def from_coefficients(cls, coefficients, variable_name="x", name=""):
""" Initiate polynomial from list of coefficients """ """ Initiate polynomial from list of coefficients
pass
:examples:
>>> P = Polynomial.from_coefficients([1, 2, 3])
>>> P
<Polynomial 3x^2 + 2x + 1>
>>> P = Polynomial.from_coefficients([1, 2, -3])
>>> P
<Polynomial - 3x^2 + 2x + 1>
>>> P = Polynomial.from_coefficients([1, 2, 3], "y")
>>> P
<Polynomial 3y^2 + 2y + 1>
"""
return cls(MOpolynomial(variable_name, coefficients), name)
@classmethod @classmethod
def random(cls): def random(cls):

View File

@ -30,7 +30,7 @@ Expression is the classe wich handle all calculus. It can randomly generate or i
""" """
from .API import Expression, Integer, Decimal, render from .API import Expression, Integer, Decimal, render, Polynomial
from .core import random_list from .core import random_list
from decimal import getcontext from decimal import getcontext
#getcontext().prec = 2 #getcontext().prec = 2