Post Reply 
HP 17B Solver - another ARCTAN(Y/X) approximation
05-31-2021, 07:30 PM
Post: #9
RE: HP 17B Solver - another ARCTAN(Y/X) approximation
For comparison, this is asin half-"angle" formula (we derive this the same way as atan):

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

RC(1-y,1) = asin(√y)/(√y) = 1 + y/6 + 3/40*y² + 5/112*y³ + 35/1152*y4 + ...

Code:
from math import sqrt
def myasin(x, verbal=False):
    y = x*x             # asin(x) = x*RC(1-y,1)
    while y > 1e-3:     # = 2*x*RC(k-y,k) = 2/sqrt(k)*x * RC(1-y/k,1)
        k = 2*(sqrt(1-y)+1)
        x *= 2/sqrt(k)
        y /= k
        if verbal: k=sqrt(y); print x/k,'* asin(',k,')'
    return x + x*y*(1/6 + y*(3/40 + y*(5/112 + y*(35/1152))))

Redo atan(1.), atan(.5) examples:

>>> x = 1.
>>> myasin(x/sqrt(1+x*x), verbal=1)
2.0 * asin( 0.382683432365 )
4.0 * asin( 0.195090322016 )
8.0 * asin( 0.0980171403296 )
16.0 * asin( 0.0490676743274 )
32.0 * asin( 0.0245412285229 )
0.78539816339744828

>>> x = .5
>>> myasin(x/sqrt(1+x*x), verbal=1)
2.0 * asin( 0.229752920547 )
4.0 * asin( 0.115652519498 )
8.0 * asin( 0.0579235119409 )
16.0 * asin( 0.0289739201537 )
0.46364760900080609
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 07:30 PM



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