Write a program to determine the real roots of a general sec
Write a program to determine the real roots of a general second-degree polynomial of the form ax^2 + bx + c. The roots of the quadratic equation ax^2 + bx + c = 0 may be found by using the quadratic formula provided below for your reference Note, D = b^2 - 4ac is known as the discriminant r_1, r_2 = -b plusorminus squareroot b^2 - 4 ac/2a = -b plusorminus squareroot D/2a The roots (r_1, r_2) may be classified according to the value of the discriminant D as follows: When D is positive, the equation ax^2 + bx + c = 0 has two real-valued and distinct roots. When D is zero, the equation ax^2 + bx + c = o has two real-valued but repeated roots. When D is negative, the equation ax^2 + bx + c = 0 has two complex-valued and distinct roots. Your program should: Prompt the user for the scalar values of a, b, and c. Compute the value of the discriminant D. Suppress any Command Window output Display the number of real-valued roots according to value of D. Utilize a conditional if-end statement. When the polynomial has real-valued roots, compute those root values Suppress any Command Window output. When the polynomial has real-valued roots, display those roots as real numbers showing a maximum of 3 digits after the decimal point for each root value.
Solution
a = input(\'Enter a value for coefficient a: \');
b = input(\'Enter a value for coefficient b: \');
c = input(\'Enter a value for coefficient c: \');
D = (b^2) - (4*a*c)
if (D < 0)
disp(\'The polynomial has complex roots.\');
elseif(D == 0)
r1 = -b/(2*a);
r2 = -b/(2*a);
fprintf(\'The polynomial has two repeated real roots\ \');
fprintf(\'Root r1 = %.3f and Root r2 = %.3f\ \', r1, r2);
else
r1 = (-b + sqrt(D))/(2*a);
r2 = (-b - sqrt(D))/(2*a);
fprintf(\'The polynomial has two distinct real roots\ \');
fprintf(\'Root r1 = %.3f and Root r2 = %.3f\ \', r1, r2);
end
