v=5; t=3; L=5; g=9.81; hl=0.01; %initial value hu=10; %initial value tolerance=0.0001; error=1;hrold=1; %for loop initiation steps=0; %for loop counting while (error > tolerance) steps=steps+1; hr= (hu+hl)/2; error=abs((hr-hrold)/hr)*100; hrold=hr; fhl=v/sqrt(2*g*hl) - tanh(t*sqrt(2*g*hl)/(2*L)); fhr=v/sqrt(2*g*hr) - tanh(t*sqrt(2*g*hr)/(2*L)); if (fhr*fhl<0) hu=hr; else hl=hr; end end root=hr error steps