change coef to coefs in Polynom

This commit is contained in:
Lafrite 2015-03-06 16:51:43 +01:00
parent b6eccba836
commit 0423cca5aa
2 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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)))