Fixed point iteration to find the roots of 0=x-tan(x)

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
51 replies · 30K views
Still off course. So let's get back on course. You are trying to find solutions to

[tex]x=\tan x[/tex]

using a fixed point iteration approach. That technique won't work with the above because tan'(x)>=1. Taking the inverse tangent function of both sides doesn't quite work, either, because atan(tan(x)) is only equal to x if x lies in the principal domain of atan.

You have already written x as [itex]x=n\pi + \theta[/itex]. Substituting this on both sides of the above equation yields

[tex]n\pi + \theta=\tan(n\pi + \theta) = \tan\theta[/tex]

By design, [itex]\theta\,\in\,(0,\pi/2)\,\forall n>0[/itex] In other words, theta is in the principal domain of atan, so you now can take the inverse tangent of both sides of the above. Do that.
 
Physics news on Phys.org
Alright, so
atan(n[tex]\pi[/tex] + [tex]\theta[/tex])= (n[tex]\pi[/tex] +[tex]\theta[/tex]) = [tex]\theta[/tex]
So theta is periodic like the sin or cos functions?
 
No. Theta is just a variable here.

You do not know that [itex]\arctan(\tan(n\pi+\theta))=n\pi+\theta[/itex]. In fact, this is not true. The domain of arctan is -pi/2 to pi/2 (at least as implemented in most programming languages). However, you do know that [itex]\tan(n\pi+\theta)=\tan\theta[/itex] due to trig identities.
 
Ok. Does arctan (tan ([tex]\theta))=\theta[/tex]?
If it does, then arctan (n*pi + [tex]\theta[/tex])=([tex]\theta[/tex]). I think I'm going in circles.
 
Brendy said:
Ok. Does arctan (tan ([tex]\theta))=\theta[/tex]?
It does if theta is in the principal domain of arctan. That was the point of creating that variable: to ensure that it does lie in the principal domain of arctan.

If it does, then arctan (n*pi + [tex]\theta[/tex])=([tex]\theta[/tex]). I think I'm going in circles.
Yes, you are. So, one step at a time.
  1. You want to find the positive solutions to [itex]x=\tan x[/itex].
  2. This is in the right form for fixed point iteration, but a fixed point iteration using the above will not converge.
  3. Taking the inverse tangent of both sides doesn't help immediately because all solutions but the trivial solution lie outside the principal domain of arctan.
  4. So, introduce a new variable that will be in the principal domain: [itex]x\equiv n\pi+\theta[/itex].
  5. Now the problem becomes one of solving [itex]n\pi+\theta = \tan(n\pi+\theta)[/itex].
  6. The right hand side of the above, [itex]\tan(n\pi+\theta)[/itex], reduces to [itex]\tan\theta[/itex] via the trig identity [itex]\tan(a+b) = (\tan a + \tan b)/(1-\tan a \tan b)[/itex].
  7. Now the problem becomes one of solving [itex]n\pi+\theta = \tan\theta[/itex].
  8. And now you can safely apply the arc tangent function to both sides because, by design, theta is in the principal domain of arctan.

Try to take it from here.
 
Last edited:
Isn't that what I wrote above? arctan ([itex]n\pi+\theta) = \theta\[/itex]
 
I thought that was taking it forward? I'm sorry, I really don't know what I'm after in this question.
My first instinct is to get everything in terms of x which would mean that arctan(x) = theta but I see that I did that a few posts ago but that was going off course and it doesn't really get me anywhere.
 
You seem to have lost sight of the goal of this problem, which is to find an equation of the form [itex]x=f(x)[/itex] than can be used in a fixed point iteration scheme. You need f(x) to involve arctan, not tangent.

This isn't that hard. Look at step 7 in post number 35.
 
Right.
arctan [itex](x) = x - n\pi\[/itex]
so,
[itex]x = arctan (x) + n\pi\[/itex]

This actually looks correct for once.
 
arctan [itex] (n\pi+\theta) = \theta\<br /> [/itex]
That's as far as I can get in solving it. I'm not sure how to proceed from there.
 
You're there. If you don't see it, just exchange the left and right hand sides. (use the fact that if a=b then b=a).
 
[itex] \theta\ = arctan (n\pi+\theta) <br /> [/itex]
So that's it? Do I try and get everything in terms of x now or is this what the algorithm will use?
 
Do you mean at the end of running the algorithm? Also, when I solve for x, the x represents the roots, right? Not just another initial guess? Or do I use what I find x to be as the next initial guess?
 
You use a different value for n to find the next root. It doesn't really matter what you use for an initial guess, so long as it is somewhere between 0 and pi/2, exclusive of the end points.

That said, it's not too hard to form a very good guess. The solution for theta will be close to pi/2 (very close for large n). Writing the solution for some particular n as [itex]\theta_n[/itex],

[tex]\theta_n = \frac{\pi}2 - \epsilon_n[/tex]

Thus [itex]\tan\theta_n = 1/\tan\epsilon_n \approx 1/\epsilon_n[/itex] if [itex]\epsilon_n[/itex] is small (which it will be).

See if you can take it from here. Or just use some value between 0 and pi/2 as your initial guess.
 
Thanks a lot, you've been a massive help.
One last thing, what are f_old and f_new doing in my code? After I edit the line x_new... to the expression for theta, it will converge on a root but I'm not sure what those two lines after that mean. Are they needed?
Also, is it supposed to converge so quickly? At the moment, it converges on the first root within 5 iterations with 1 as an initial guess.
 
Last edited:
You wrote that code; you are the one who should know what it is doing. You will of course have to rewrite your code to use this new formula.

Last thing: I wouldn't bother with the trivial solution. You know that solution, and a fixed point iteration scheme isn't really valid for finding the trivial solution because it sits right at a point where tan'(x)=atan'(x)=1. The derivative has to be strictly less than one for a fixed point iteration to converge.
 
I didn't write the code. I modified an existing program that was solving x_n+1 = e^-x_n
Which solution are you referring to? Even changing the initial guess to something further away from the root such as 0.5 sees it converging within 6 iterations.
 
That algorithm doesn't converge. I just took your code from post #17; it stopped after 50 iterations because it failed to converge.

Look at it this way: [itex]\tan x \approx x(1 - x^2/3)[/itex] for small x. All setting [itex]x=\arctan(x)[/itex] does when x gets even close to zero is to scale x by a factor that is nearly equal to 1.
 
After rewriting it so that x_new... line is now x_new= atan (pi + x_old) it converged within 6 iterations. So is that just a fluke then? It is giving me the correct number to find the roots though.
I don't follow post #51 at all I'm sorry.