1
$\begingroup$

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}$$

$\endgroup$

1 Answer 1

1
$\begingroup$

The secant method converges almost as fast as the Newton method, and this one reaches machine precision in 1-5 iterations. So as long as you pick an initial value close enough to the root, you shouldn't have to worry about exiting the loop too soon.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .