>> diary >> format long >> eps ans = 2.220446049250313e-16 >> bisection( 'myfunction', 0.0, pi/2, 1.0e-5, 100, 0) ans = 0.870153597984356 >> approx_root = bisection( inline( '2/pi*exp(2*x/pi)+(1-exp(1))*cos(x)' ), 0.0, pi/2, 1.0e-5, 100, 1) iters left end midpt right end fun(midpt) log_2(bracket) 1 0.00000000000000 0.78539816339745 1.57079632679490 -1.654e-01 0.651 2 0.78539816339745 1.17809724509617 1.57079632679490 6.902e-01 -0.349 3 0.78539816339745 0.98174770424681 1.17809724509617 2.347e-01 -1.349 4 0.78539816339745 0.88357293382213 0.98174770424681 2.724e-02 -2.349 5 0.78539816339745 0.83448554860979 0.88357293382213 -7.100e-02 -3.349 6 0.83448554860979 0.85902924121596 0.88357293382213 -2.235e-02 -4.349 7 0.85902924121596 0.87130108751904 0.88357293382213 2.324e-03 -5.349 8 0.85902924121596 0.86516516436750 0.87130108751904 -1.004e-02 -6.349 9 0.86516516436750 0.86823312594327 0.87130108751904 -3.868e-03 -7.349 10 0.86823312594327 0.86976710673116 0.87130108751904 -7.741e-04 -8.349 11 0.86976710673116 0.87053409712510 0.87130108751904 7.743e-04 -9.349 12 0.86976710673116 0.87015060192813 0.87053409712510 -2.762e-08 -10.349 13 0.87015060192813 0.87034234952662 0.87053409712510 3.871e-04 -11.349 14 0.87015060192813 0.87024647572737 0.87034234952662 1.935e-04 -12.349 15 0.87015060192813 0.87019853882775 0.87024647572737 9.675e-05 -13.349 16 0.87015060192813 0.87017457037794 0.87019853882775 4.836e-05 -14.349 17 0.87015060192813 0.87016258615304 0.87017457037794 2.417e-05 -15.349 18 0.87015060192813 0.87015659404058 0.87016258615304 1.207e-05 -16.349 19 0.87015060192813 0.87015359798436 0.87015659404058 6.021e-06 -17.349 >> approx_root = 0.870153597984356 >> exact_root = bisection( inline( '2/pi*exp(2*x/pi)+(1-exp(1))*cos(x)' ), 0.0, pi/2, 1.0e-14, 100, 0) exact_root = 0.870150615609478 >> approx_root - exact_root ans = 2.982374878057747e-06 >> exact_root = bisection( inline( '2/pi*exp(2*x/pi)+(1-exp(1))*cos(x)' ), 0.0, pi/2, 1.0e-20, 100, 0) Warning: the tolerance is too small > In bisection at 14 Error in ==> bisection at 13 if tol < 3*eps % The tolerance is too small Output argument "r" (and maybe others) not assigned during call to "/home/npetrov/bisection.m>bisection". >> exit