mirror of
https://github.com/Sosokker/Calculator-for-Matrix-and-Algebra.git
synced 2025-12-19 05:04:06 +01:00
Fix Solve()
This commit is contained in:
parent
05f34c7a0b
commit
d9700f2d74
@ -1,6 +1,5 @@
|
|||||||
from parser.parser import parse_poly
|
from nessesary.parser.parser import parse_poly
|
||||||
from fraction import to_fraction
|
from nessesary.fraction import to_fraction
|
||||||
from math import sqrt
|
|
||||||
|
|
||||||
class Polynomial:
|
class Polynomial:
|
||||||
def __init__(self, poly, fracmode=False):
|
def __init__(self, poly, fracmode=False):
|
||||||
@ -181,16 +180,16 @@ class Polynomial:
|
|||||||
else:
|
else:
|
||||||
root_term = b**2-4*a*c
|
root_term = b**2-4*a*c
|
||||||
if root_term < 0:
|
if root_term < 0:
|
||||||
res1 = f"({-b}+{to_imag(sqrt(root_term))})/{2*a}"
|
res1 = f"({-b}+{to_imag(root_term**0.5)})/{2*a}"
|
||||||
res2 = f"({-b}-{to_imag(sqrt(root_term))})/{2*a}"
|
res2 = f"({-b}-{to_imag(root_term**0.5)})/{2*a}"
|
||||||
return (res1, res2)
|
return (res1, res2)
|
||||||
else:
|
else:
|
||||||
if root_term == 0:
|
if root_term == 0:
|
||||||
return (-b/(2*a), None)
|
return (-b/(2*a), None)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
res1 = (-b-sqrt(root_term))/(2*a)
|
res1 = (-b-(root_term)**0.5)/(2*a)
|
||||||
res2 = (-b+sqrt(root_term))/(2*a)
|
res2 = (-b+(root_term)**0.5)/(2*a)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
res1 = (-b-(root_term)**0.5)/(2*a)
|
res1 = (-b-(root_term)**0.5)/(2*a)
|
||||||
res2 = (-b+(root_term)**0.5)/(2*a)
|
res2 = (-b+(root_term)**0.5)/(2*a)
|
||||||
@ -206,7 +205,7 @@ def to_imag(num) -> str:
|
|||||||
>>> to_imag(-10.12)
|
>>> to_imag(-10.12)
|
||||||
'10.12i'
|
'10.12i'
|
||||||
"""
|
"""
|
||||||
num = abs(float(num))
|
num = abs(num)
|
||||||
return f"{num}i"
|
return f"{num}i"
|
||||||
|
|
||||||
# p1 = Polynomial("x^2+2x+1", fracmode=True)
|
# p1 = Polynomial("x^2+2x+1", fracmode=True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user