the question goes something like this :
Apply the bisection method using the code in slides to find the root of the function $f(x) = \sqrt{x} − 1.1$ starting from the interval $[0, 2]$ with a tolerance of $\epsilon = 1.e-8$
- How many iterations are required ? Does the iteration count match the expectations, based on our convergence analysis ?
- What is the resulting absolute error ? Could this absolute error be predicted by our convergence analysis ?
the first part of the question is pretty easy to code out and here is my code for the same :
def func(x):
return np.sqrt(x)-1.1
def bisection(a, b, tol):
if (func(a) * func(b) >= 0):
return
c = a
itercount=0
while ((b-a) >= tol):
c = (a+b)/2
if (func(c) == 0.0):
return c
if (func(c)*func(a) < 0):
b = c
else:
a = c
itercount+=1
return c, itercount
we get the theoretical number of iterations using the relation $n_{_{theoretical}} = \log_{_{2}} \left( \frac{b-a}{\epsilon}\right)$ which is very close to that counted by the programme ( $n_{_{calculated}} = 28$).
the absolute error = $8.94 \cdot 10^{-10}$ , but I have a problem understanding how this error could have been predicted by the convergence analysis, any hints or solutions are welcome.