>>>For the purpose of my class, "math unlimited" (see download section), I can't use the built-in atan() function. Instead, I have to program it myself, using an infinite series.
>>>
>>>The problem is, the series I find in books only works for arguments <= 1. That is, it will only work if the resulting angle has an absolute value of <= 45 degrees. And for arguments approaching 1, the infinite series will converge very slow.
>>>
>>>Does anyone know of a conversion function, to reduce, for instance, atan(2) to an atan() of smaller angles?
>>>
>>>And, does anybody know conversion functions, or infinite series, to obtain asin() and acos()?
>>>
>>>Hilmar.
>>
>>Hilmar,
>>
>>I am sending you a mail, with a 2 scanned pages (jpg)
>>If I start tyoing I'll will make mistakes
>>
>>
>>The right hand page gives
>>asin
>>acos
>>atan ( x^2 < 1)
>>atan ( x > 1)
>>atan ( x < -1)
>
>Dankjewel. I believe I can use the formulae for asin() and acos(). With the formulae for atan() I can, in theory, calculate atan() for any value; however, I am still worried about slow convergence for calculations like atan(0.999), where the argument is very close to 1.
>
>An extreme case is the calculation of pi() based on atan(1):
>
>pi() / 4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 ...
>
>It should be obvious that it will take an eternity to get a reasonable approximation.
>
>Hilmar.
atan_(.999) goes in .083 ms (P III 500 MHz).
procedure do_it()
set decimals to 18
xx = _atan(.999)
?xx
?tan(xx)
endproc
function _atan(x)
local i, Result, OldResult, y, xSquare
do case
case x = 1.00
return pi()/4.0
case x == -1.00
return -(pi()/4.0)
case empty(x)
return Null
case between (x, -1.00, 1.00)
xSquare = x*x
Result = x
y = x
OldResult = Result
for i = 3 to (2^31 - 1) step 4
y = y * xSquare
Result = Result - y/i
y = y * xSquare
Result = Result + y/(i+2)
if( Result = OldResult )
return Result
endif
OldResult = Result
endfor
assert FALSE
return Null
otherwise
xSquare = x*x
y = x
Result = sign(x) * (pi()/2) - 1/x
OldResult = Result
for i = 3 to (2^31 - 1) step 4
y = y * xSquare
Result = Result + 1/(i * y)
y = y * xSquare
Result = Result - 1/((i+2) * y)
if( Result = OldResult )
return Result
endif
OldResult = Result
endfor
assert FALSE
return Null
endcase
endfunc
Gregory