I want to write a Matlab code which calculates the root of a given function using the secant method.
Having somewhat studied the method, I know that, depending on various conditions, there is a possibility the it may not converge.
Keeping that in mind, I want to determine a number of maximum iterations after which I will exit my loop no matter whether the precision I want is achieved or not.
However, I don't want to exit too soon, therefore breaking the loop before it converges, nor too late therefore making the program inefficient.
Any ideas as to how I can determine a satisfactory number of maximum iterations, if there is one?
The loop is as follows : $$x_{1+1} = x_i - \frac{f(x_i)(x_i-x_{i-1})}{f(x_i) - f(x_{i-1})}$$
until $$x_{i+1} < \text{precision}$$