diff --git a/pymath/polynom.py b/pymath/polynom.py index 1355e0d..51e4ea2 100644 --- a/pymath/polynom.py +++ b/pymath/polynom.py @@ -64,9 +64,9 @@ class Polynom(Explicable): # On "parse" ce string pour créer les coefs coefs = [eval(i) if type(i)==str else i for i in eval(coefs)] # Création du polynom - return Polynom(coef = coefs, letter = letter) + return Polynom(coefs = coefs, letter = letter) - def __init__(self, coef = [1], letter = "x" ): + def __init__(self, coefs = [1], letter = "x" ): """Initiate the polynom :param coef: coefficients of the polynom (ascending degree sorted) @@ -86,7 +86,7 @@ class Polynom(Explicable): 'y' """ super(Polynom, self).__init__() - self.feed_coef(coef) + self.feed_coef(coefs) self._letter = letter diff --git a/pymath/polynomDeg2.py b/pymath/polynomDeg2.py index 1efd025..517a889 100644 --- a/pymath/polynomDeg2.py +++ b/pymath/polynomDeg2.py @@ -4,8 +4,10 @@ from .polynom import Polynom from .expression import Expression from .operator import op +from .random_expression import RdExpression from math import sqrt +__all__ = ["Polynom_deg2"] class Polynom_deg2(Polynom): @@ -13,6 +15,26 @@ class Polynom_deg2(Polynom): Child of Polynom with some extra tools """ + @classmethod + def random(self, coefs_form = ["{c}", "{b}", "{a}"], conditions = [], letter = "x"): + """ Create a 2nd degree poly from coefs_form ans conditions + + :param coefs_form: list of forms (one by coef) (ascending degree sorted) + :param conditions: condition on variables + :param letter: the letter for the polynom + + """ + if len(coefs_form) != 3: + raise ValueError("Polynom_deg2 have to be degree 2 polynoms, they need 3 coefficients, {} are given".format(len(coefs_form))) + + form = str(coefs_form) + # On créé les valeurs toutes concaténées dans un string + coefs = RdExpression(form, conditions)() + # On "parse" ce string pour créer les coefs + coefs = [eval(i) if type(i)==str else i for i in eval(coefs)] + # Création du polynom + return Polynom_deg2(coefs = coefs, letter = letter) + def __init__(self, coefs = [0, 0, 1], letter = "x"): if len(coefs) < 3 or len(coefs) > 4: raise ValueError("Polynom_deg2 have to be degree 2 polynoms, they need 3 coefficients, {} are given".format(len(coefs)))