• Support PF! Buy your school textbooks, materials and every day products Here!

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

  • Thread starter Brendy
  • Start date
  • #26
38
0
So x=n*pi + theta. How do I determine what theta is? Theta<pi/2 but only by a little and it approaches pi/2 as n approaches infinity. I don't know how to find an exact solution though.
 
  • #27
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
You aren't going to find an exact solution. You need to use some estimation algorithm -- such as a fixed point iteration algorithm. With x=n*pi + theta, what does x=tan(x) say about theta?
 
  • #28
38
0
Since tan(n*pi)=0 it says that x=tan (theta)? Theta=arctan (x). So tan(theta)=n*pi +arctan(x). I'm I veering off course? It kind of feels like it :P
 
  • #29
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
Since tan(n*pi)=0 it says that x=tan (theta)?
Correct.
Theta=arctan (x). So tan(theta)=n*pi +arctan(x). I'm I veering off course? It kind of feels like it :P
Veering off course. Make the substitution on both sides of the equality, and remember that a fixed point iteration based on tangent is not stable. You need to use atan.

Don't worry about x until you have found theta.
 
  • #30
38
0
so n*pi<tan(theta)<(n+1/2)pi. So, atan(n*pi) < theta < atan((n+1/2)pi) and atan(n*pi)=~1.263, atan((n+1/2)pi=~1.362 so 1.263<theta<1.362.
That narrows it down a fair bit. I'm not sure what the exact forms of atan(n*pi) and atan((n+1/2)pi) are though.
 
  • #31
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.
 
  • #32
38
0
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?
 
  • #33
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.
 
  • #34
38
0
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.
 
  • #35
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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:
  • #36
38
0
Isn't that what I wrote above? arctan ([itex] n\pi+\theta) = \theta\
[/itex]
 
  • #37
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
Fine. Can you take it forward from post#35?
 
  • #38
38
0
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.
 
  • #39
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.
 
  • #40
38
0
Right.
arctan [itex] (x) = x - n\pi\ [/itex]
so,
[itex] x = arctan (x) + n\pi\ [/itex]

This actually looks correct for once.
 
  • #41
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
That's not right. Forget about x! You need to solve for theta.
 
  • #42
38
0
arctan [itex]
(n\pi+\theta) = \theta\

[/itex]
That's as far as I can get in solving it. I'm not sure how to proceed from there.
 
  • #43
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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).
 
  • #44
38
0
[itex]
\theta\ = arctan (n\pi+\theta)

[/itex]
So that's it? Do I try and get everything in terms of x now or is this what the algorithm will use?
 
  • #45
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
That's it. You will solve for x at the very end.
 
  • #46
38
0
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?
 
  • #47
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.
 
  • #48
38
0
Thanks alot, 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:
  • #49
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.
 
  • #50
38
0
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.
 

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

Replies
17
Views
11K
Replies
9
Views
473
Replies
1
Views
19K
Replies
2
Views
10K
Replies
1
Views
926
Replies
3
Views
3K
  • Last Post
Replies
1
Views
595
  • Last Post
Replies
2
Views
1K
Replies
1
Views
613
Top