2. Identify the potential roundoff error problems in the following algorithm for
calculating the roots of the quadratic equation ax2+bx +c= 0.
GIVEN: real coefficients a,b,c
STEP 1: calculate disc =√b2−4ac
STEP 2: calculate root1 = (−b+disc)/(2a)
STEP 3: calculate root2 = c/(a·root1)
OUTPUT: root1 and root2
Note that this algorithm uses the fact that the product of the roots of ax2+
bx +c= 0 is equal to c/a.
3. Identify the potential roundoff error problems in the following algorithm for
calculating the roots of the quadratic equation ax2+bx +c= 0.
GIVEN: real coefficients a,b,c
STEP 1: calculate disc =√b2−4ac
STEP 2: calculate root1 = −2c/(b+disc)
STEP 3: calculate root2 = −(b/a)−root1
OUTPUT: root1 and root2
Note that this algorithm uses the fact that the sum of the roots of ax2+bx+c= 0
is equal to −b/a.
4. Construct an algorithm which computes the roots of the quadratic equation
ax2+bx +c= 0 and which avoids as many roundoff error problems as possible.
Test your algorithm by computing the roots of the quadratic equations 0.2x2−
47.91x+ 6 = 0 and 0.025x2+ 7x−0.1 = 0. Use 4 decimal digit rounding
arithmetic in your calculations.