(-12+√(b^2-4ac))/2a
(where a = 1, b = 5, c = 3)
How do I write a code for a quadratic equation?
(-12+√(b^2-4ac))/2a
(where a = 1, b = 5, c = 3)
How do I write a code for a quadratic equation?
Okay, we can have three notions in here:
With all that in mind, I can show an example in a simple language is python how works in practice:
import cmath
a = 1
b = 5
c = 3
delta = (b**2) - (4*a*c)
root1 = (-b-cmath.sqrt(delta))/(2*a)
root2 = (-b+cmath.sqrt(delta))/(2*a)
print('The solution are {0} and {1}'.format(root1 ,root2))
the result will be
The solution are (-4.302775637731995) and (-0.6972243622680054)
In python
a=1
b=5
c=3
value = (-12+(b**2-4*a*c)**(1/2))/(2*a)
print(value)
This outputs the answer as -4.197224362268005