1. ## Programming challenge

The cubic function ax^2 + bx + c achieves the value 0 for certain values of x (called the roots of the cubic) – these depend on the parameters a, b, c, and d. Note that unlike a quadratic function, a cubic function is guaranteed to have at least one real root. Your job is to numerically find one root of the cubic using an efficient search method called “the bisection method”. This works as follows.

The bisection method operates by creating an interval that contains the root we seek, and then repeatedly shrinking that interval so that we “home in” on the solution. First, we choose two numbers, l and u. For starters, you may choose, for example, l = -10 and u=10 . These guesses are chosen such that f(l) and f(u) have different signs. This means the root we seek must lie in the interval between l and u . The trick underpinning the bisection method is to consider the midpoint m= (l+u)/2. If f(x) changes sign between m and u , then the root must lie between these two points, and therefore our interval should shrink accordingly – we can achieve this by setting m to be the new value of l. If, on the other hand, f(x) changes sign between l and m, then the root must lie between these two points – so we set m to be the new value of u . We continue this procedure until the search interval becomes extremely small, at which point the value of m will provide a good estimate of the root.

The program should be called root.c and program execution should look like the following (user input in bold):

************************************************ Welcome to the cubic root estimator. This estimates the value of one root of f(x)=ax^3+bx^2+cx+d. ************************************************

Enter the coefficients in the form “a b c d”: 1 -3 -3 -4

There is a root at: x = 4.000 Do you wish to try another cubic [y/n]: n

2. Looks more like homework than challenge.