Skip to content

Commit c15a1c7

Browse files
committed
Add polynom file
1 parent a2a98fe commit c15a1c7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pypolynom/pypolynom/polynom.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding: utf-8
2+
3+
"""This is a simple demonstration library"""
4+
5+
__authors__ = ["Pierre Knobel", "Jerome Kieffer", "Pierre Palero",
6+
"Henri Payno", "Armando Sole", "Valentin Valls",
7+
"Thomas Vincent"]
8+
__date__ = "01/04/2019"
9+
__license__ = "MIT"
10+
11+
12+
from . import mathutil
13+
14+
15+
def polynom(a, b, c):
16+
"""Solve the polygon of order two.
17+
18+
.. math:: a\cdotx^2 + b\cdotx + c = 0
19+
20+
:param float a: a value of the polynom
21+
:param float b: b value of the polynom
22+
:param float c: c value of the polynom
23+
:rtype: List[float]
24+
"""
25+
if a == 0:
26+
# Not a polynom
27+
raise ValueError("Not a quadratic equation (a==0)")
28+
delta = mathutil.pow2(b) - 4.0 * a * c
29+
solutions = []
30+
if delta > 0:
31+
solutions.append((-b + mathutil.sqrt(delta)) / (2.0 * a))
32+
solutions.append((-b - mathutil.sqrt(delta)) / (2.0 * a))
33+
elif delta == 0:
34+
solutions.append(-b/(2.0*a))
35+
return solutions

0 commit comments

Comments
 (0)