An archive of Mark's Spring 2018 Numerical Analysis course.

Section 2.1 Question 9

Bara223

Using the bisection method estimate the root of

g(x)= 2+x-e^{x}

between 1 and 2 within 0.05 of accuracy

Bara223

Great Question!

Using the bisection code, what you can do is edit the while loop to return the value when the error meets the 0.05 requirement instead of machine precision so that

while abs(a-b) > 0.05 and cnt < 100:

Running the code with

def f(x): return 2+x-np.exp(x)
bisection(f,1,2, True)

will give you the output of the value 1.15625 after 5 iterations