Feat: Init polynomial with coefficients
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ff4d8471ef
commit
cbcead48f7
@ -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')
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
<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
|
||||
def random(cls):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user