v=5; t=3; L=5; g=9.81; tolerance = 1e-5; rel_error = 1; %initial guesses xl = 0.01; xu = 10; xr = (xl + xu)/2; while (rel_error > tolerance) fxr = v/sqrt(2*g*xr) - tanh (t/(2*L)*sqrt(2*g*xr)); fxl = v/sqrt(2*g*xl) - tanh (t/(2*L)*sqrt(2*g*xl)); if (fxl*fxr<0) xu = xr; else xl = xr; end xrold = xr xr = (xl + xu)/2; rel_error =abs((xr - xrold)/xr)*100; end root = xr