Cody

# Problem 966. Bisection method of finding a root.

Solution 1755964

Submitted on 20 Mar 2019 by Sarah Meng
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
f=@(x) x.^2-4; x_lower = 1; x_upper = 3; es = 0; maxit=1; x_root_correct = 2; assert(isequal(bisection(f,x_lower,x_upper,es,maxit),x_root_correct))

new = 2 old = 2 count = 2

2   Pass
f=@(x) x.^2-4; x_lower = 1; x_upper = 4; es = 0; maxit=1; x_root = 2.5; assert(isequal(bisection(f,x_lower,x_upper,es,maxit),x_root))

x_upper = 2.5000 new = 2.5000 old = 2.5000 count = 2

3   Pass
f=@(x) x.^2-4; x_lower = 1; x_upper = 4; x_root = 2.000000476837158; assert(isequal(bisection(f,x_lower,x_upper),x_root))

x_upper = 2.5000 new = 2.5000 old = 2.5000 count = 2 x_lower = 1.7500 old = 2.5000 new = 1.7500 error = 42.8571 count = 3 x_upper = 2.1250 old = 1.7500 new = 2.1250 error = 17.6471 count = 4 x_lower = 1.9375 old = 2.1250 new = 1.9375 error = 9.6774 count = 5 x_upper = 2.0312 old = 1.9375 new = 2.0312 error = 4.6154 count = 6 x_lower = 1.9844 old = 2.0312 new = 1.9844 error = 2.3622 count = 7 x_upper = 2.0078 old = 1.9844 new = 2.0078 error = 1.1673 count = 8 x_lower = 1.9961 old = 2.0078 new = 1.9961 error = 0.5871 count = 9 x_upper = 2.0020 old = 1.9961 new = 2.0020 error = 0.2927 count = 10 x_lower = 1.9990 old = 2.0020 new = 1.9990 error = 0.1466 count = 11 x_upper = 2.0005 old = 1.9990 new = 2.0005 error = 0.0732 count = 12 x_lower = 1.9998 old = 2.0005 new = 1.9998 error = 0.0366 count = 13 x_upper = 2.0001 old = 1.9998 new = 2.0001 error = 0.0183 count = 14 x_lower = 1.9999 old = 2.0001 new = 1.9999 error = 0.0092 count = 15 x_upper = 2.0000 old = 1.9999 new = 2.0000 error = 0.0046 count = 16 x_lower = 2.0000 old = 2.0000 new = 2.0000 error = 0.0023 count = 17 x_upper = 2.0000 old = 2.0000 new = 2.0000 error = 0.0011 count = 18 x_lower = 2.0000 old = 2.0000 new = 2.0000 error = 5.7221e-04 count = 19 x_upper = 2.0000 old = 2.0000 new = 2.0000 error = 2.8610e-04 count = 20 x_lower = 2.0000 old = 2.0000 new = 2.0000 error = 1.4305e-04 count = 21 x_upper = 2.0000 old = 2.0000 new = 2.0000 error = 7.1526e-05 count = 22