Post Reply 
HP 17B Solver - another ARCTAN(Y/X) approximation
05-31-2021, 04:42 PM
Post: #8
RE: HP 17B Solver - another ARCTAN(Y/X) approximation
(05-16-2021 05:04 PM)Albert Chan Wrote:  I was wondering ... is there a half-"angle" atan formula ? atan(x) = 2*atan(h) + atan(ε)

Yes ! And, we can remove the messy ε Smile

Carlson symmetric elliptic integrals: atan(x) = x * RC(1, 1+x²)

We apply duplicate theorem, with λ = 2*√(1+x²) + (1+x²) = k-1

atan(x)
= x * RC(1, 1+x²)
= 2*x * RC(1+λ, 1+x²+λ)
= 2*x * RC(k, k+x²)
= 2*x/√k * RC(1, 1+x²/k)
= 2*x/√k * atan(x/√k) / (x/√k)
= 2 * atan(x/√k)

\(\displaystyle\arctan(x) = 2\arctan\left( {x \over \sqrt{2\sqrt{1+x^2}+x^2+2}} \right)\)

We can apply formula repeatedly, until argument of atan is small.

RC(1,1+y) = atan(√y)/(√y) = 1 - y/3 + y²/5 - y³/7 + ...

Code:
from math import sqrt
def myatan(x, verbal=False):
    y = x*x             # atan(x) = x*RC(1,1+y)
    while y > 1e-3:     # = 2*x*RC(k,k+y) = 2*x/sqrt(k) * RC(1,1+y/k)
        k = y + 2*(sqrt(1+y)+1)
        x *= 2/sqrt(k)
        y /= k
        if verbal: k=sqrt(y); print x/k,'* atan(',k,')'
    return x - x*y*(1/3 - y*(1/5 - y*(1/7 - y*(1/9))))

>>> myatan(1., verbal=1)
2.0 * atan( 0.414213562373 )
4.0 * atan( 0.19891236738 )
8.0 * atan( 0.0984914033572 )
16.0 * atan( 0.0491268497695 )
32.0 * atan( 0.0245486221089 )
0.78539816339744861

>>> myatan(.5, verbal=1)
2.0 * atan( 0.2360679775 )
4.0 * atan( 0.116433821466 )
8.0 * atan( 0.0580209276916 )
16.0 * atan( 0.0289860894461 )
0.46364760900080626
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-31-2021 04:42 PM



User(s) browsing this thread: 1 Guest(s)