Re: Atan[(tan(x)^2+tan(y)^2)^0.5] - Numeric approximation
- To: mathgroup at smc.vnet.net
- Subject: [mg16827] Re: Atan[(tan(x)^2+tan(y)^2)^0.5] - Numeric approximation
- From: John Doty <jpd at w-d.org>
- Date: Tue, 30 Mar 1999 02:35:24 -0500
- Organization: The Internet Access Company, Inc.
- References: <7ct3cu$84t@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Alberto Zardin wrote: > > Is there somebody who knows how to approximate the function > > teta=arctan[ sqrt( tan(x)^2+ tan(y)^2 ) ^0.5 ] > > to be used in assembly language for microcontroller? This is not a good candidate for a polynomial approximation: 1. It has branch points at the origin and everywhere where either x or y is Pi/2 (and an infinity of other more remote points). Polynomials usually don't make efficient approximants in the vicinity of branch points. 2. Polynomials tend to be inefficient approximants for for functions of more than one variable. I sometimes approximate functions like this by finding a crude approximant with all the singularities near the desired domain in the right places, and then fitting a polynomial correction. Mathematica is very handy for this kind of thing. However, in this case I think there's a better way: Replace Tan[x] with the ratio Sin[x]/Cos[x]. Put the resulting sum of ratios under the radical together as a single ratio with a common denominator. Replace the square root of the ratio with a ratio of square roots. Use the two argument arctangent on the resulting ratio. You'll get: 2 2 ArcTan[Cos[x] Cos[y], Sqrt[Cos[y] Sin[x] + 2 2 Cos[x] Sin[y] ]] This is, of course, exactly the same function you wrote, but now it's written in terms of elementary functions that can be easily approximated in fixed point on a microcontroller. Type "cordic sin cos" into your favorite internet search engine. The CORDIC methodology can be used for a wide variety of trigonometric calculations, and is well suited to microcontroller implementation. You'll only need to implement two CORDIC-based functions: one that given "a" delivers Sin[a] and Cos[a], and one that given "x" and "y" delivers ArcTan[x,y] and Sqrt[x^2+y^2]. -- John Doty "You can't confuse me, that's my job." Home: jpd at w-d.org Work: jpd at space.mit.edu