Bisection https://en.wikipedia.org/wiki/Bisection_method Read also about other root-finding algorithms https://en.wikipedia.org/wiki/Root-finding_algorithms The task: Write the program that (using the bisection algorithm) will find the root for the function: f(x) = x^3 - x - 2 See the section "Example: Finding the root of a polynomial" in https://en.wikipedia.org/wiki/Bisection_method Starting interval: [1,2] The output of the program should look like the table there (showing individual steps and the convergence towards the solution): ============================================= Step a b c f(c) 1 1.00000 2.00000 1.50000 -0.1250000 2 1.50000 2.00000 1.75000 1.6093750 3 1.50000 1.75000 1.62500 0.6660156 4 1.50000 1.62500 1.56250 0.2521973 The value of root is: 1.5625000000 with 0.1000 precision ============================================= Step a b c f(c) 1 1.00000 2.00000 1.50000 -0.1250000 2 1.50000 2.00000 1.75000 1.6093750 3 1.50000 1.75000 1.62500 0.6660156 4 1.50000 1.62500 1.56250 0.2521973 5 1.50000 1.56250 1.53125 0.0591125 6 1.50000 1.53125 1.51562 -0.0340538 7 1.51562 1.53125 1.52344 0.0122504 The value of root is: 1.5234375000 with 0.0100 precision ============================================= Step a b c f(c) 1 1.00000 2.00000 1.50000 -0.1250000 2 1.50000 2.00000 1.75000 1.6093750 3 1.50000 1.75000 1.62500 0.6660156 4 1.50000 1.62500 1.56250 0.2521973 5 1.50000 1.56250 1.53125 0.0591125 6 1.50000 1.53125 1.51562 -0.0340538 7 1.51562 1.53125 1.52344 0.0122504 8 1.51562 1.52344 1.51953 -0.0109712 9 1.51953 1.52344 1.52148 0.0006222 10 1.51953 1.52148 1.52051 -0.0051789 11 1.52051 1.52148 1.52100 -0.0022794 12 1.52100 1.52148 1.52124 -0.0008289 13 1.52124 1.52148 1.52136 -0.0001034 14 1.52136 1.52148 1.52142 0.0002594 The value of root is: 1.5214233398 with 0.0001 precision ============================================= Extra task: Implement the children's game "guess a number." The scorer has a secret number, and will only tell the player if the guessed number is higher than, lower than, or equal to the secret number. The player then uses this information to guess a new number. The exemplary terminal output should look like (200 is the quess): ---------------------------------------------------------------- Think of a number between 1 and 1000 and wait for me to guess it. After every guess, state whether the guess was too high (h), too low (l), or correct (c) to your number. Guess 1 is: 500. The score for which is (h,l,c): h Guess 2 is: 250. The score for which is (h,l,c): h Guess 3 is: 125. The score for which is (h,l,c): l Guess 4 is: 187. The score for which is (h,l,c): l Guess 5 is: 218. The score for which is (h,l,c): h Guess 6 is: 202. The score for which is (h,l,c): h Guess 7 is: 194. The score for which is (h,l,c): l Guess 8 is: 198. The score for which is (h,l,c): l Guess 9 is: 200. The score for which is (h,l,c): c It took 9 attempts. ---------------------------------------------------------------- Other examples: http://isoelectric.org/www_old/files/practise-isoelectric-point.html