function [ root, iteration_info ] = bisection( f, a, b, eps )
% Arguments:
% [a, b] - interval, a < b
% f - continuous function defined on [a, b], f(a) and f(b) have opposite signs
% eps - max error
% Returns:
% root - found root
% iteration_info - matrix of size (number_of_iterations)x5; row layout: [iteration, a, c, b, c - a]
iteration = 0;
iteration_info = [];
while true
iteration = iteration + 1;
c = (a + b) / 2;
iteration_info(iteration, :) = [iteration, a, c , b, c - a];
if c - a <= eps
break
end
if f(a) * f(c) < 0
b = c;
else
a = c;
end
end
root = c;
end
format short g
[result
, info
] = bisection
(@
(x
)(x
+log(2*x
)), 0.2, 0.75, 0.00005)
ZnVuY3Rpb24gWyByb290LCBpdGVyYXRpb25faW5mbyBdID0gYmlzZWN0aW9uKCBmLCBhLCBiLCBlcHMgKQolIEFyZ3VtZW50czoKJSAgW2EsIGJdIC0gaW50ZXJ2YWwsIGEgPCBiCiUgIGYgICAgICAtIGNvbnRpbnVvdXMgZnVuY3Rpb24gZGVmaW5lZCBvbiBbYSwgYl0sIGYoYSkgYW5kIGYoYikgaGF2ZSBvcHBvc2l0ZSBzaWducwolICBlcHMgICAgLSBtYXggZXJyb3IKJSBSZXR1cm5zOgolICByb290ICAgICAgICAgIC0gZm91bmQgcm9vdAolICBpdGVyYXRpb25faW5mbyAtIG1hdHJpeCBvZiBzaXplIChudW1iZXJfb2ZfaXRlcmF0aW9ucyl4NTsgcm93IGxheW91dDogW2l0ZXJhdGlvbiwgYSwgYywgYiwgYyAtIGFdCgppdGVyYXRpb24gPSAwOwppdGVyYXRpb25faW5mbyA9IFtdOwp3aGlsZSB0cnVlCiAgaXRlcmF0aW9uID0gaXRlcmF0aW9uICsgMTsKICBjID0gKGEgKyBiKSAvIDI7CiAgaXRlcmF0aW9uX2luZm8oaXRlcmF0aW9uLCA6KSA9IFtpdGVyYXRpb24sIGEsIGMgLCBiLCBjIC0gYV07CiAgCiAgaWYgYyAtIGEgPD0gZXBzCiAgICBicmVhawogIGVuZAogIAogIGlmIGYoYSkgKiBmKGMpIDwgMAogICAgYiA9IGM7CiAgZWxzZQogICAgYSA9IGM7CiAgZW5kCmVuZApyb290ICA9IGM7CmVuZAoKZm9ybWF0IHNob3J0IGcKW3Jlc3VsdCwgaW5mb10gPSBiaXNlY3Rpb24oQCh4KSh4K2xvZygyKngpKSwgMC4yLCAwLjc1LCAwLjAwMDA1KQ==