MATLAB: How to count how many iterations the root is in a smaller interval

bisectionmethod

In my code I need to display in the command line how many of the iterations my root was in the smaller interval. I am not entirely sure what this means, but I'm hoping someone does and can give me a hand to work out what I'm missing. At the moment the command line displays the same number of iterations for both the iterations to the root and how many iterations the root was in the smaller interval.
Code removed. Question has been answered.

Best Answer

In each iteration you have two intervals, [a,c] and [c,b]. Compute the size of both intervals and use the last if-else condition in your code to increment itc.