Post Reply 
HP-35 style trig functions
08-29-2023, 05:39 AM
Post: #13
RE: HP-35 style trig functions
I had to slightly adjust the algorithm:
Code:
from math import sqrt, atan, asin

N = 16
ATAN  = [atan(10**(-i)) for i in range(1, N)]

P, d = 1.0, 0.1
for i in range(1, N):
    P *= (1 + d*d)
    d /= 10

K = sqrt(P)**9

def cmp(a, b):
    return (a > b) - (a < b)

def arcsin(z, d, A):
    x, y = 1/K, 0
    arg = 0
    for a in A:
        for _ in range(9):
            s = cmp(z, y)
            arg += s * a
            x, y = x - y * s * d, y + x * s * d
        d /= 10
    return x, y, arg

To calculate \(\sin^{-1}(0.4)\) use:
Code:
z = 0.4
arcsin(z, 0.1, ATAN)

(0.9165151389911695, 0.3999999999999998, 0.4115168460674864)

Compare it to the proper value:
Code:
asin(z)

0.41151684606748806

Also note that \(x = \cos(\arg)\) is calculated as well.
But you can ignore this unless you need it.

Just a few notes:
  • I had to skip the first value in ATAN. Otherwise \(1/K\) is too small and we'd spiral once around the origin before hitting \(z\).
  • As a consequence the input range is limited to \(0 \le z < 0.8\).
  • I haven't figured out the proper value yet. It might be slightly above that.
  • They dropped the cmp function in Python 3 so I had to provide that.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP-35 style trig functions - Druzyek - 01-13-2019, 08:32 PM
RE: HP-35 style trig functions - pier4r - 01-13-2019, 08:37 PM
RE: HP-35 style trig functions - Druzyek - 01-14-2019, 12:56 AM
RE: HP-35 style trig functions - Dan - 01-14-2019, 01:31 AM
RE: HP-35 style trig functions - Druzyek - 01-14-2019, 02:34 AM
RE: HP-35 style trig functions - Dan - 01-15-2019, 03:43 AM
RE: HP-35 style trig functions - Druzyek - 01-15-2019, 11:49 PM
RE: HP-35 style trig functions - Druzyek - 08-28-2023, 12:19 AM
RE: HP-35 style trig functions - Thomas Klemm - 08-29-2023 05:39 AM



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