start working on deg 2 polynoms

This commit is contained in:
Lafrite 2015-01-23 17:19:14 +01:00
parent f00d8c9e57
commit 9649a0dbaf
2 changed files with 96 additions and 0 deletions

65
pymath/polynomDeg2.py Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/env python
# encoding: utf-8
from .polynom import Polynom
from .expression import Expression
from .operator import op
from math import sqrt
class Polynom_deg2(Polynom):
""" Degree 2 polynoms
Child of Polynom with some extro tools
"""
def __init__(self, coefs = [0, 0, 1], letter = "x"):
"""@todo: to be defined1. """
Polynom.__init__(self, coefs, letter)
@property
def a(self):
return self._coef[2]
@property
def b(self):
return self._coef[1]
@property
def c(self):
return self._coef[0]
@property
def delta(self):
"""Compute the discriminant expression
:returns: discriminant expression
"""
return Expression([self.b, 2, op.pw, 4, self.a, self.c, op.mul, op.mul, op.sub])
def roots(self):
"""Compute roots of the polynom
"""
if self.delta > 0:
roots = [(-self.b - sqrt(self.delta)
if __name__ == '__main__':
from .render import txt
with Expression.tmp_render(txt):
P = Polynom_deg2([2, 3, 4])
print(P)
print("Delta")
for i in P.delta.simplify():
print(i)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

31
test/test_polynomDeg2.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
# encoding: utf-8
import unittest
from pymath.polynomDeg2 import Polynom_deg2
class TestPolynomDeg2(unittest.TestCase):
"""Testing functions from pymath.polynomDeg2"""
pass
if __name__ == '__main__':
unittest.main()
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del