Given a quadratic equation the task is solve the equation or find out the roots of the equation. Standard form of quadratic equation is – ax2 + bx + c where, a, b, and c are coefficient and real numbers and also a ≠ 0. If a is equal to 0 that equation is not valid quadratic equation. Examples:
Method 1: Using the direct formula Using the below quadratic formula we can find the root of the quadratic equation. There are following important cases. If b*b < 4*a*c, then roots are complex (not real). For example roots of x2 + x + 1, roots are -0.5 + i1.73205 and -0.5 - i1.73205 If b*b == 4*a*c, then roots are real and both roots are same. For example, roots of x2 - 2x + 1 are 1 and 1 If b*b > 4*a*c, then roots are real and different. For example, roots of x2 - 7x - 12 are 3 and 4
0 1 2
4 5 4 7 8 9 If b*b < 4*a*c, then roots are complex (not real). For example roots of x2 + x + 1, roots are -0.5 + i1.73205 and -0.5 - i1.73205 If b*b == 4*a*c, then roots are real and both roots are same. For example, roots of x2 - 2x + 1 are 1 and 1 If b*b > 4*a*c, then roots are real and different. For example, roots of x2 - 7x - 12 are 3 and 40 9 If b*b < 4*a*c, then roots are complex (not real). For example roots of x2 + x + 1, roots are -0.5 + i1.73205 and -0.5 - i1.73205 If b*b == 4*a*c, then roots are real and both roots are same. For example, roots of x2 - 2x + 1 are 1 and 1 If b*b > 4*a*c, then roots are real and different. For example, roots of x2 - 7x - 12 are 3 and 42 4 8 real and different roots 2.0 -12.01 real and different roots 2.0 -12.02 real and different roots 2.0 -12.03 real and different roots 2.0 -12.04
real and different roots 2.0 -12.06
real and different roots 2.0 -12.08 real and different roots 2.0 -12.09 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)0 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)1 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)5 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)6 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)9 9 `# Python program to find roots of quadratic equation` 2 `# Python program to find roots of quadratic equation` 3`# Python program to find roots of quadratic equation` 4The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6 `# Python program to find roots of quadratic equation` 8The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)9
`# Python program to find roots of quadratic equation` 3`# Python program to find roots of quadratic equation` 4The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6 `# Python program to find roots of quadratic equation` 8real and different roots 2.0 -12.04
`math ` 3 7 8
The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)0 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)1 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 ` ` 2The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)6 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4
`# Python program to find roots of quadratic equation` 4 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6 `# Python program to find roots of quadratic equation` 8real and different roots 2.0 -12.04
` ` 6
` ` 8` ` 9The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 03 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)6 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4
`# Python program to find roots of quadratic equation` 4 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6 14 15 16 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4
`# Python program to find roots of quadratic equation` 4 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6 14 27 16
30
33
36 37
40
42 real and different roots 2.0 -12.08
The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)0 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)1 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)2 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)3 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 52 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)6
58 Output: real and different roots 2.0 -12.0 Method 2: Using the complex math module First, we have to calculate the discriminant and then find two solution of quadratic equation using cmath module. 59
61
33
37
`# Python program to find roots of quadratic equation` 6
73 7
76 `# Python program to find roots of quadratic equation` 680 The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 87
89 90
The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4
96 `# Python program to find roots of quadratic equation` 4The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6
The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4
`# Python program to find roots of quadratic equation` 2 96 `# Python program to find roots of quadratic equation` 4The roots are (-3.414213562373095+0j) (-0.5857864376269049+0j)4 `# Python program to find roots of quadratic equation` 6 |