Let's consider the function f(x)= tan(x)- x and its root in the interval (Pi/2,3*Pi/2)
Firstly, we zoom the intersection point of the function with g(x)= tan(x) and h(x)= x ( or the function f(x) and the Ox axis):
plot([tan(x),x], x= 4.3..4.55, gridlines=true);
Now, we use the Newton-Raphson method to reach the root, like this:
restart: f:= x -> x-tan(x); a[-1]:= 0: a[0]:= 4.55: # a[0]= 4.55 since we obtain the root is close to 4.55 N:= 0: while abs(a[N]-a[N-1])>10^(-9) do a[N+1]:= a[N]- f(a[N])/fdiff(f(x), x=a[N]) ; N:=N+1 od: print(); 'N'=N; 'a[N]'= a[N]; 'f(a[N])'= f(a[N]);
Then, of course, it certainly reach the root.
However the problem is that how can I find an interval, as large as possible, in which any starting value (i.e a[0]) generates a sequence that converges to the solution?
Is there any other theorem that improve such interval? Or we just use heudristics?
NR
The function should be neither too flat not too steep, since
you divide by f'(x[n]) and actually a code would check that.
Beyond that the theory says: do not start at inflection points.
But practical ...
So an answer would be: there is no guarantee that it works
and if not ... try another method ...
"Numerical Recipies" shows some, Google may give you
links for some downloads of that book.
PS: you should not use fdiff here, try D(f).