Post Reply 
HP-12C trigonometrics revisited
10-15-2017, 08:00 PM (This post was last modified: 10-17-2017 06:39 PM by tycho.)
Post: #1
HP-12C trigonometrics revisited
I recently bought my first HP-12C - brand new from ebay (serial CNA5...). I must say the build quality seems excellent and the speed is amazing. So I wanted to implement Valentin Albillo's trigonometric functions from the excellent "HP-12C Tried & Tricky Trigonometrics", but realized that the program has some major limitations in input ranges and usability for some of the functions.
Valentin's program usage:
Code:
Function:            To compute, press:          Input range                    . 
Sin(x)               x, GTO 00, R/S, x<>y        -5*Pi  to  +5*Pi 
Cos(x)               x, GTO 00, R/S              -Pi/2  to  +Pi/2 
Tan(x)               x, GTO 00, R/S, /           -Pi/2  to  +Pi/2 
ArcSin(x)            x, GTO 37, R/S              -1  to  +1 
ArcCos(x)            x, GTO 93, R/S               0  to  +1 
ArcTan(x)            x, GTO 30, R/S              -9.99E49  to  +9.99E49 
the constant Pi/2    GTO 92, R/S

Using arguments outside -Pi/2 - Pi/2 may give wrong signs for Cos(x) and Tan(x), which is an obvious drawback. The other gripe I have is that it is very hard to remember those GTO lines for the Arc functions and Pi/2, as well as remembering that the default function (from step 00) returns Cos(x) and not Sin(x) which would be more intuitive for me at least.

The challenge was that Valentin's program already used the max 99 steps. With some tricks I managed to modify it, while still keeping it within max.
NEW (easier to remember) program usage and wider input ranges:
Code:
Function:            To compute, press:            Input range                    . 
Sin(x)               x, GTO 01, R/S                -5*Pi  to  +5*Pi 
Cos(x)               x, GTO 02, R/S                -5*Pi  to  +5*Pi 
Tan(x)               x, R/S, x, GTO 02, R/S, /     -5*Pi  to  +5*Pi 
ArcSin(x)            x, GTO 03, R/S                -1  to  +1 
ArcCos(x)            x, GTO 03, R/S, x<>y          -1  to  +1 
ArcTan(x)            x, GTO 04, R/S                -9.99E49  to  +9.99E49 
the constant Pi/2    RCL 0
---
init. store Pi/2     1, GTO 03, R/S, STO 0

Tan(x) is still not ideal. However, it takes "full range" input and gives correct sign - likewise with Cos(x). The program uses REG 4, 5, 6, like Valentin's, but additionally requires Pi/2 to be stored in REG 0 in order for Cos(x) and ArcCos(x) to work. Pi/2 = ArcSin(1), so to quickly store it in REG 0, type:
Code:
1
GTO 03
R/S
STO 0

On my new HP-12C, the functions returns answers almost instantly, probably as fast or faster than an HP-15C! The full program list:
Code:
01    GTO 73   ' Sin
02    GTO 71   ' Cos
03    GTO 11   ' ArcSin + ArcCos
04    ENTER    ' ArcTan(x) = ArcSin(x/Sqrt(1+x^2)) 
05    ENTER   
06    *      
07    1      
08    +      
09  g SQRT  
10    /
11    STO 4    ' START ArcSin(x)
12    3      
13    x<>y     ' LOOP1
14    ENTER   
15     *      
16    CHS     
17    1      
18    +      
19  g SQRT  
20    CHS     
21    1      
22    +      
23    2      
24    /  
25    STO 5       
26  g SQRT  
27    x<>y    
28    1      
29    -      
30  g x=0?  
31  g GTO 33
32  g GTO 13   ' END LOOP1
33  g n!
34    STO 6   
35    RCL 5   
36    -      
37  g SQRT  
38    /      
39    STO 5   
40    RCL 5    ' LOOP2
41    CHS     
42    STO 5   
43    RCL 6   
44    2      
45    +      
46    STO 6   
47    y^x     
48  g LSTx  
49    /
50    + 
51    - 
52  g x=0? 
53  g GTO 56
54  g LSTx 
55  g GTO 40   ' END LOOP2
56    RCL 4
57  g x<=y? 
58  g GTO 68
59  g LSTx 
60    8
61    *        
62    STO 5    ' END ArcSin(x)
63    RCL 0    ' START ArcCos(x) = Pi/2 – ArcSin(x)
64    -
65    CHS
66    RCL 5    ' x: ArcSin, y: ArcCos
67  g GTO 00   ' END ArcCos(x)
68  g LSTx
69    CHS 
70  g GTO 60
71    RCL 0    ' START Cos(x) = Sin(x + Pi/2), x in [–5*Pi .. 5*Pi]
72    +
73    STO 5    ' START Sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ..., x in [–5*Pi .. 5*Pi]
74    1              
75    STO 6           
76    RCL 5            
77    RCL 5    ' LOOP3
78    CHS             
79    STO 5           
80    RCL 6           
81    2               
82    +              
83    STO 6           
84    y^x             
85  g LSTx            
86  g n!            
87    /              
88    +               
89    -              
90  g x=0?          
91  g GTO 94
92  g LSTx
93  g GTO 77   ' END LOOP3
94  g LSTx
95    RCL 4
96    x<>y     ' x: Sin/Cos, y: last Sin/Cos
97    STO 4    ' END Sin(x)
98    GTO 00
Find all posts by this user
Quote this message in a reply
Post Reply 




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