Post Reply 
Arctangent function program [HP-42S, Free42]
09-21-2024, 05:31 PM (This post was last modified: 09-21-2024 06:27 PM by Albert Chan.)
Post: #29
RE: Arctangent function program [HP-42S, Free42]
Slightly improved Thomas code (previous post)
Note: no changes done to tan(x/2) calculations

sin(x) * tan(x/2) = 2*sin(x/2)*cos(x/2) * sin(x/2)/cos(x/2) = 2*sin(x/2)^2 = versine(x) = 1 - cos(x)

Code:
00 { 63-Byte Prgm } ; x
01 2                ; 2     x
02 X<>Y             ; x     2
03 ÷                ; x/2
04 STO 00           ; a = x/2
05 STO 01           ; b = a
06 1                ; 1
07 STO 02           ; p = 1
08 CLX              ; 0
09 STO 03           ; q = 0
10 STO 04           ; w = 0
11 8                ; 8
12 STO 05           ; n = 8
13▸LBL 00           ; for loop
14 RCL 00           ; a
15 RCL 01           ; b     a
16 STO 00           ; a = b
17 2                ; 2     b       a
18 ×                ; 2b    a
19 +                ; a+2b
20 +/-              ; -(a+2b)
21 STO 01           ; b = -(a+2b)
22 RCL 02           ; p
23 RCL 04           ; w     p
24 STO 02           ; p = w
25 RCL 00           ; a     w       p
26 ×                ; a*w   p
27 +                ; a*w+p
28 STO 04           ; w = a*w+p
29 RCL 00           ; a
30 RCL 03           ; q      a
31 +                ; a+q
32 1/X              ; 1/(a+q)
33 STO 03           ; q = 1/(a+q)
34 STO× 02          ; p = w*q
35 STO× 04          ; w = (a*w+p)*q
36 DSE 05           ; n = n-1
37 GTO 00           ; repeat
38 RCL 04           ; t = tan(x/2)
39 ENTER

40 ENTER
41 +
42 LASTX
43 ENTER
44 ×             
45 1                ; 1    t^2  2t   t
46 +                
47 ÷                ; sin(x) t            t   t
48 STO× ST Y        ; sin(x) versine(x)   t   t
49 1                
50 RCL- ST Z        ; cos(x) sin(x) versine(x) tan(x/2)
51 END

PI 6 / R/S                  ; x = pi/6

T = 0.267949192431 ; tan(x/2)
Z = 0.133974596216 ; versine(x)
Y = 0.5                     ; sin(x)
X = 0.866025403784 ; cos(x)

Update: replaced "X↑2" by "Enter ×" (reason, see next post)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Arctangent function program [HP-42S, Free42] - Albert Chan - 09-21-2024 05:31 PM



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