The Museum of HP Calculators

HP Forum Archive 21

 Trig Identity questionMessage #1 Posted by Namir on 3 Mar 2013, 10:34 a.m. Hi All, Anyone knows of a trig identity between the arc tangent of an angle and it's multiples, like: arctan(2x) = function of arctan(x) Thanks! Namir PS: I have found a polynomial approximation by Eurler to calculate arctan very accurately, but I require tens of thousands of terms!!!!! Ouch!

 Re: Trig Identity questionMessage #2 Posted by Thomas Klemm on 3 Mar 2013, 11:20 a.m.,in response to message #1 by Namir Used WolframAlpha with: ```Taylor[arctan[2*tan[y]],y] ``` The result is: ```2 y-2 y^3+4 y^5-(142 y^7)/15+(4612 y^9)/189-(312644 y^11)/4725+O(y^12) ``` But that's probably not what you are looking for: a simple formula. HTH Thomas If you do it with the inverse order of the functions: ```Taylor[tan[2*arctan[y]],y] ``` The result is: ```2 y+2 y^3+2 y^5+2 y^7+2 y^9+2 y^11+O(y^12) (converges when abs(y)<1) ``` This geometric series leads to the well known result: $\tan(2x)=\frac{2\tan x}{1-\tan^{2}x}$ Edited: 3 Mar 2013, 1:08 p.m.

 Re: Trig Identity questionMessage #3 Posted by Namir on 3 Mar 2013, 4:19 p.m.,in response to message #2 by Thomas Klemm I am looking for an equation that is similar to the one for tan(2x) but expressed in terms of arctan(2x) and arctan(x). I have a good Pade Approximant for tan(x). Ultimately, I can can use the Pade approximant for tan(x) in an iterative process. That would still be much faster than calculating 3000 to 4000 terms in a slow converging polynomial. Namir Edited: 3 Mar 2013, 4:22 p.m.

 Re: Trig Identity questionMessage #4 Posted by Gerson W. Barbosa on 3 Mar 2013, 5:10 p.m.,in response to message #3 by Namir Quote: I am looking for an equation that is similar to the one for tan(2x) but expressed in terms of arctan(2x) and arctan(x). This doesn't appear to be possible. From the identity #1 here I've obtained $\arctan (x)=\frac{1}{2}\arctan \left ( \frac{2x}{1-x^{2}} \right )$ and $\arctan (2x)=2 \arctan \left ( \frac{\sqrt{4x^{2}+1}-1}{2x} \right )$ None of which will serve your purpose, though. Edited to correct a typo in the second equation Edited: 3 Mar 2013, 7:07 p.m.

 Re: Trig Identity questionMessage #5 Posted by Thomas Klemm on 3 Mar 2013, 6:00 p.m.,in response to message #3 by Namir It may not be clear from my answer but the solution is: ```arctan(2x) = 2 arctan(x) - 2 arctan3(x) + 4 arctan5(x) + ... ``` This is not the formula you are looking for but its Taylor expansion. So all you need to do is find a closed formula of this series. I didn't made any attempts to find it but just from looking at the coefficients of the higher orders I doubt that there is any. It's not that you can expect that there is a closed formula in general. In the case of tan(x) it is related to the multiplication of complex numbers. Sorry for the bad news. Cheers Thomas

 Re: Trig Identity questionMessage #6 Posted by Namir on 4 Mar 2013, 7:16 a.m.,in response to message #5 by Thomas Klemm I found the following useful identity: arctan(x) = pi/2 - arctan(1/x) This identity allows me to calculate the arctan for high values (just below 90 degrees) by calculating the arctan of 1/x. I can calculate arctan with good accuracy for low x values using polynomial approximations or iteratively. Either way, I get good results for high x values! Namir Edited: 4 Mar 2013, 7:22 a.m.

 Re: Trig Identity questionMessage #7 Posted by Namir on 4 Mar 2013, 11:06 a.m.,in response to message #1 by Namir I found an efficient algorithm to calculate arctan(x). ```EPS = 1e-8 A1 = 1/SQRT(1+x*x) B1 = 1 Do A0 = A1 B0 = B1 A1 = (A0+B0)/2 B1 = SQRT(A1*B0) Loop until |A1-A0|<=EPS and |B1-B0|<=EPS arctan(x) = x/(SQRT(1+x*x)*A1) ``` Algorithm works as efficiently for small and large values of x. Number of iterations for the above loop range from 11 to 15. Edited: 4 Mar 2013, 11:08 a.m.

 Re: Trig Identity questionMessage #8 Posted by Thomas Klemm on 4 Mar 2013, 6:34 p.m.,in response to message #7 by Namir I'm glad you found something useful. That's an interesting algorithm which reminds me of the arithmetic–geometric mean. However there's a slight difference: ```B1 = SQRT(A1*B0) ``` instead of ```B1 = SQRT(A0*B0) ``` In the Wikipedia article is a reference to the article: B. C. Carlson (1972). "An algorithm for computing logarithms and arctangents". Math.Comp. 26 (118): 543–549. Was that your source? Kind regards Thomas

 Re: Trig Identity questionMessage #9 Posted by Paul Dale on 4 Mar 2013, 6:39 p.m.,in response to message #8 by Thomas Klemm Without coding and testing anything, I wonder if the difference is significant. The AGM converges pretty quickly which would mean A0 -> A1. - Pauli

 Re: Trig Identity questionMessage #10 Posted by Paul Dale on 4 Mar 2013, 6:53 p.m.,in response to message #9 by Paul Dale A quick check and they do converge different after all. - Pauli

 Re: Trig Identity questionMessage #11 Posted by Namir on 4 Mar 2013, 7:57 p.m.,in response to message #8 by Thomas Klemm My source was the Wolfram web site. Edited: 4 Mar 2013, 7:59 p.m.

 Re: Trig Identity questionMessage #12 Posted by Thomas Klemm on 4 Mar 2013, 8:45 p.m.,in response to message #11 by Namir Acton, F. S. "The Arctangent." In Numerical Methods that Work, upd. and rev. Washington, DC: Math. Assoc. Amer., pp. 6-10, 1990. Unfortunately without further explanations. Cheers Thomas

 Re: Trig Identity questionMessage #13 Posted by Namir on 4 Mar 2013, 11:08 p.m.,in response to message #12 by Thomas Klemm That's the same algorithm I found on the Wolfram web site. It works well even for large values of x. There is no need to use the trick: arctan(x) = pi/2 - arctan(1/x) Namir Edited: 4 Mar 2013, 11:09 p.m.

 Re: Trig Identity questionMessage #14 Posted by Eric Smith on 4 Mar 2013, 7:45 p.m.,in response to message #7 by Namir The CORDIC algorithm is another efficient way of computing arctangents with few iterations, but it requires a precomputed table of coefficients. In another post you mentioned wanting the arctan of high values. If what you need is the angle given an x and y coordinate, i.e., the atan2(y,x) function, CORDIC is very good for that as well, since you don't have to do the y/x division, which can lose a lot of precision.

Go back to the main exhibit hall