In summary, the conversation discusses strategies for finding the roots of the function y=x-tan(x). The first step is to graph the function and estimate the roots visually. Then, a fixed point method is suggested for finding the first four positive roots. The conversation also addresses the issue of the roots getting farther apart as x increases, and suggests using a starting point close to odd multiples of pi/2 for finding the next root. The conversation concludes with a discussion about implementing these strategies in code.
#36
Brendy
38
0
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.
#40
Brendy
38
0
Right.
arctan [itex] (x) = x - n\pi\ [/itex]
so,
[itex] x = arctan (x) + n\pi\ [/itex]
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.
#48
Brendy
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.
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
Brendy
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.
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.
#52
Brendy
38
0
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.