From 68bac4e1d4187658d7c6dd458628749ef9efb1c2 Mon Sep 17 00:00:00 2001 From: AugustofCravo <49079453+AugustofCravo@users.noreply.github.com> Date: Tue, 2 Jul 2019 20:32:53 -0300 Subject: [PATCH 1/2] Create Quadratic Equations(Complexes Numbers) Created function that solves quadratic equations treating the cases with complexes numbers. Giving an answer with the imaginary unit "i". --- maths/Quadratic Equations(Complexes Numbers) | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 maths/Quadratic Equations(Complexes Numbers) diff --git a/maths/Quadratic Equations(Complexes Numbers) b/maths/Quadratic Equations(Complexes Numbers) new file mode 100644 index 000000000000..f05b938fefe9 --- /dev/null +++ b/maths/Quadratic Equations(Complexes Numbers) @@ -0,0 +1,39 @@ +import math + +def QuadraticEquation(a,b,c): + """ + Prints the solutions for a quadratic equation, given the numerical coefficients a, b and c, + for a*x*x + b*x + c. + Ex.: a = 1, b = 3, c = -4 + Solution1 = 1 and Solution2 = -4 + """ + Delta = b*b - 4*a*c + if a != 0: + if Delta >= 0: + Solution1 = (-b + math.sqrt(Delta))/(2*a) + Solution2 = (-b - math.sqrt(Delta))/(2*a) + print ("The equation solutions are: ", Solution1," and ", Solution2) + else: + """ + Treats cases of Complexes Solutions(i = imaginary unit) + Ex.: a = 5, b = 2, c = 1 + Solution1 = (- 2 + 4.0 *i)/2 and Solution2 = (- 2 + 4.0 *i)/ 10 + """ + if b > 0: + print("The equation solutions are: (-",b,"+",math.sqrt(-Delta),"*i)/2 and (-",b,"+",math.sqrt(-Delta),"*i)/", 2*a) + if b < 0: + print("The equation solutions are: (",b,"+",math.sqrt(-Delta),"*i)/2 and (",b,"+",math.sqrt(-Delta),"*i/",2*a) + if b == 0: + print("The equation solutions are: (",math.sqrt(-Delta),"*i)/2 and ",math.sqrt(-Delta),"*i)/", 2*a) + else: + print("Error. Please, coeficient 'a' must not be zero for quadratic equations.") +def main(): + a = 5 + b = 6 + c = 1 + + QuadraticEquation(a,b,c) # The equation solutions are: -0.2 and -1.0 + + +if __name__ == '__main__': + main() From e5a28b937687f37759bec7ce8a14a5d4f83e30d7 Mon Sep 17 00:00:00 2001 From: Harshil Date: Tue, 6 Aug 2019 02:18:11 +0200 Subject: [PATCH 2/2] Update Quadratic Equations(Complexes Numbers) Since there was no response from the owner of this PR, I made this little change which I hope will solve the issue! --- maths/Quadratic Equations(Complexes Numbers) | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/Quadratic Equations(Complexes Numbers) b/maths/Quadratic Equations(Complexes Numbers) index f05b938fefe9..8e8e78fec68f 100644 --- a/maths/Quadratic Equations(Complexes Numbers) +++ b/maths/Quadratic Equations(Complexes Numbers) @@ -1,3 +1,4 @@ +from __future__ import print_function import math def QuadraticEquation(a,b,c):