diff --git a/mapytex/__init__.py b/mapytex/__init__.py index 86007bd..1d83226 100644 --- a/mapytex/__init__.py +++ b/mapytex/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # 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') diff --git a/mapytex/calculus/API/__init__.py b/mapytex/calculus/API/__init__.py index 1502cdf..572d097 100644 --- a/mapytex/calculus/API/__init__.py +++ b/mapytex/calculus/API/__init__.py @@ -125,6 +125,7 @@ x^7 from .expression import Expression from .tokens import Token +from .tokens.polynomial import Polynomial from .tokens.number import Integer, Decimal, Fraction from .renders import render diff --git a/mapytex/calculus/API/tokens/polynomial.py b/mapytex/calculus/API/tokens/polynomial.py index 4be7203..035f662 100644 --- a/mapytex/calculus/API/tokens/polynomial.py +++ b/mapytex/calculus/API/tokens/polynomial.py @@ -15,6 +15,7 @@ from .token import Token from . import to_be_token from ...core.MO import MO from ...core.MO.atoms import moify +from ...core.MO.polynomial import MOpolynomial __all__ = ["Polynomial", "Quadratic", "Linear"] @@ -44,9 +45,21 @@ class Polynomial(Token): return cls(mo, name, ancestor) @classmethod - def from_coefficients(cls, coefficients): - """ Initiate polynomial from list of coefficients """ - pass + def from_coefficients(cls, coefficients, variable_name="x", name=""): + """ Initiate polynomial from list of coefficients + + :examples: + >>> P = Polynomial.from_coefficients([1, 2, 3]) + >>> P + + >>> P = Polynomial.from_coefficients([1, 2, -3]) + >>> P + + >>> P = Polynomial.from_coefficients([1, 2, 3], "y") + >>> P + + """ + return cls(MOpolynomial(variable_name, coefficients), name) @classmethod def random(cls): diff --git a/mapytex/calculus/__init__.py b/mapytex/calculus/__init__.py index 7c1f9e9..a81db68 100644 --- a/mapytex/calculus/__init__.py +++ b/mapytex/calculus/__init__.py @@ -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 decimal import getcontext #getcontext().prec = 2