The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
(71B) Approximation for Tan(x) for the HP-71B
09-25-2017, 08:03 PM (This post was last modified: 09-27-2017 01:17 PM by Namir.)
Post: #1
(71B) Approximation for Tan(x) for the HP-71B
This is an approximation for tan(x) using a sequence of polynomial coefficients that I found in a book "A Handbook of Integer Sequences" by A. J. A Sloane that presents numerous sequences of integers. The book does cover a few approximation to functions, including tan(x). Here is the code for the HP-71B. When you run the program, it prompts you to enter a value of X. The program then displays the calculated value of tan(x), pauses for 3 seconds, and then displays the %$ error. The function offers excellent approximation for (0, 0.35). You can use trig identities to calculate the tan(x) for higher angles using accurate tan(x) for smaller x values, for example, using:

tan(x) = 2*tan(x/2)/(1 + tan(x/2)^2)

Here is the HP-71B listing.

Code:
10 REM TAN(X) APPROXIMATION
20 RADIANS @ N=12
30 DIM C(12)
40 FOR I = 1 TO N @ READ C(I) @ NEXT I
50 INPUT "X? ";X
60 S = 0
70 P = X
80 X2 = X * X
90 FOR I = 1 TO N
100 S = S + C(I) * P / FACT(2*I-1)
110 P = P * X2
120 NEXT I
130 DISP "TAN(";X;")=";S @ WAIT 3
140 T=TAN(X)
150 DISP "%ERR=";100*(T-S)/T
160 DATA 1, 2, 16, 272, 7936, 353792, 22368256
170 DATA 1903757312, 209865342976
180 DATA 29088885112832, 4.9514980531241E+15, 1.01542388650685E+18
190 END

Here is another version that combines the original sequence and the factorials

Here is the HP-71B listing.

Code:
10 REM TAN(X) APPROXIMATION
20 RADIANS @ N=12
30 DIM C(12)
40 FOR I = 1 TO N @ READ C(I) @ NEXT I
50 INPUT "X? ";X
60 S = 0
70 P = X
80 X2 = X * X
90 FOR I = 1 TO N
100 S = S + C(I) * P 
110 P = P * X2
120 NEXT I
130 DISP "TAN(";X;")=";S @ WAIT 3
140 T=TAN(X)
150 DISP "%ERR=";100*(T-S)/T
160 DATA 1, 0.333333333333333, 0.133333333333333
162 DATA 0.053968253968254, 0.0218694885361552
164 DATA  0.0088632355299022, 0.00359212803657248
170 DATA 0.00145583438705132, 0.000590027440945586
180 DATA 0.000239129114243552, 0.0000969153795692946
182 DATA 0.0000392783238833167
190 END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(71B) Approximation for Tan(x) for the HP-71B - Namir - 09-25-2017 08:03 PM



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