From: "Hermann Kremer" Subject: Re: Approximation to teta=arctg y/x Date: Thu, 24 Aug 2000 19:44:25 +0200 Newsgroups: sci.math.num-analysis jvilhena schrieb in Nachricht <8nv62n$531$1@srvlis16.teleweb.pt>... >I need an expression to approximate teta=arctg y/x in function of z=y/x. I >need only values for teta in the interval [0,Pi/2]. >The expression can contain only simple operators, like +, -, x, /, ^ and >root. >Does anyone know one good approximation, a book that treats this kind of >problems, or even a site? > Approximate arctan(z) , -oo < z < +oo Let s = 1 for z > 0, s = 0 for z = 0, s = -1 for z < 0 , Let u = |z| for 0 <= |z| <=1, u = 1/|z| for |z| > 1 , Let v = u for 0 <= u <= 0.26795, v = sqrt(3) - 4/(u + sqrt(3)) otherwise , Let P = A - B*v^2 + C/( v^2 + D - E/(v^2 + F) ) , Let Q = v*P for 0 <= u < 0.26795, Q = v*P + pi/6 otherwise , Then arctan(z) = s*Q for 0 <= |z| <= 1 , arctan(z) = s*(pi/2 - Q) for |z| > 1 Where A = 0.428 408 163 270 B = 0.017 414 965 986 C = 1.164 132 944 600 D = 2.211 165 206 100 E = 0.242 371 744 720 F = 1.388 834 793 900 Regards Hermann -- >-- > >Best Regards >jvilhena ============================================================================== From: kovarik@mcmail.cis.McMaster.CA (Zdislav V. Kovarik) Subject: Re: Approximation to teta=arctg y/x Date: 24 Aug 2000 21:36:45 -0400 Newsgroups: sci.math.num-analysis In article <8nv62n$531$1@srvlis16.teleweb.pt>, jvilhena wrote: :I need an expression to approximate teta=arctg y/x in function of :z=y/x. I need only values for teta in the interval [0,Pi/2]. :The expression can contain only simple operators, like +, -, x, /, ^ :and root. :Does anyone know one good approximation, a book that treats this kind :of problems, or even a site? : (1) (How simple is simple?) Do you allow conditional operations? (2) Is the square root available to you accurate to your satisfaction, and cheap in terms of time? (3) How accurate is the approximation required to be? Suppose you can answer "yes" to (1) and (2), and your answer to (3) would be "I want complete control over the accuracy within a tolerance tol>0 supplied by me" then there is a hand-made pseudocode based on angle halving and the well-known observation that arctan(z) is close to z within z^3/3: the variable m scales the value back, accounting for the halving. It is assumed that tol is less than 1 (it will be something like 10^(-k) anyway) m := 1 s := z while m*s^3 > 3*tol s := s / (1 + sqrt(1 + s^2)) m := 2*m end result := m*s If you want to economize on square roots, here is a refinement (one of a list of such) using more terms of the power series, which by the way is arctan(z) = z - z^3/3 + z^5/5 - z^7/7 + z^9/9 - ... convergent for abs(z)<1 and whose truncation error is less than the magnitude of the first neglected term: m := 1 s := z while m*s^7 > 7*tol s := s / (1 + sqrt(1 + s^2)) m := 2*m end result := m*((3*s^2 - 5) * s^2 + 1)*s / 15 Care should be exercised with the powers: m*s^3 and 1+s^2 can lead quickly to an overflow for large starting value of s. Fortunately, right after first angle-halving, s is less than 1 anyway. So, if z>1, you play it safe with m := 2 s := 1/z s := 1/(s + sqrt(1+s^2)) and go about the while-loop and conclusion as before. Cheers, ZVK(Slavek)