Question
Write a program in Python that reads in the coefficients of a 2nd degree polynomial and prints the roots. The formula for the roots of
Write a program in Python that reads in the coefficients of a 2nd degree polynomial and prints the roots. The formula for the roots of the quadratic polynomial ax2+bx+c = 0 are (-b + sqrt(b2-4ac))/2a and (-b - sqrt(b2-4ac))/2a Since the value of b2-4ac can be negative, we need to use complex numbers. By import cmath module then we get the csqrt function which gives us the square root of a complex number. This function is used like this: x = cmath.sqrt( y ) where y is some number (positive or negative) and x is assigned a value such that x2 = y. Sample example: Coefficient a: 1 Coefficient b: -10 Coefficient c: 5 Polynomial: 1.0 x^2 + -10.0 x + 5.0 Root 1: (9.47213595499958+0j) Root 2: (0.5278640450004204+0j) Coefficient a: 1 Coefficient b: -4 Coefficient c: 0 Polynomial: 1.0 x^2 + -4.0 x + 0.0 Root 1: (4+0j) Root 2: 0j Coefficient a: 1 Coefficient b: 2 Coefficient c: 3 Polynomial: 1.0 x^2 + 2.0 x + 3.0 Root 1: (-1+1.4142135623730951j) Root 2: (-1-1.4142135623730951j) Coefficient a: 10 Coefficient b: 0 Coefficient c: 0 Polynomial: 10.0 x^2 + 0.0 x + 0.0 Root 1: 0j Root 2: 0j Coefficient a: -4 Coefficient b: 30 Coefficient c: 170 Polynomial: -4.0 x^2 + 30.0 x + 170.0 Root 1: (-3.770804478245662-0j) Root 2: (11.270804478245662-0j)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started