Ahmed - theta is your xmid and I think that you are calculating it correctly (see https://en.wikipedia.org/wiki/Bisection_method for details). One issue may be with your tolerance err
err = 0.477;
Why is this such a large value? If I leave your code as is, then the condition for
while err_bisect > err
is never true so the bisection method doesn't do anything. Try reducing err to somethig much smaller (perhaps 0000477) and then the code will iterate 12 times and give you an answer of 49.732039 which f(49.732039) ~= 0. Same with
ferr=0.176;
Why such a large number? Shouldn't this be close to zero too?