Trigonometric Functions (HP-17BII)
#1

Here is a new set of trigonometric functions equations for the HP-17BII. These are based upon approximations for both sine and cosine involving a few Taylor series terms and the correspondent hyperbolic functions, as discussed here last week.

SIN=(1-2*IP((MOD(X:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:MOD(X:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)

COS=(1-2*IP((MOD(X+90:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:MOD(X+90:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)

TAN=(4*SIGMA(K:1:21:4:(L(A:MOD(X:180)*PI/180))^K/FACT(K))-EXP(G(A))+EXP(-G(A)))/
(4*SIGMA(K:0:20:4:(L(A:MOD(X:180)*PI/180))^K/FACT(K))-EXP(G(A))-EXP(-G(A)))

The equations are short enough to be quickly keyed into the calculator without mistakes. Arguments in degrees up to +/- 999 999 999 999 are accepted for SIN and TAN (The range is slightly shorter for COS because it is computed as SIN shifted 90 degrees).
The maximum absolute error for SIN should be in theory 3.5*10-13 (2*pi^25/25! -- that is close to what is obtained on the HP-200LX solver as can be seen in the third plot), but in practice the HP-17BII, a 12-digit calculator (four less than the HP-200LX solver), can deliver results accurate to 10 or 11 results only. When working next to its accuracy level, the HP-200LX loses about two digits of accuracy (second plot).

The running times are very good: about 1.1 second for SIN and COS and 2.2 seconds for TAN. Of course the inverse functions can also be calculated, but this will take longer and will depend on the initial guess.

Plots of SIN, COS and TAN on the HP-200LX:


The second plot shows the difference of the SIN equation in relation to the built-in SIN function (in degrees mode), when seven terms of the Taylor series are used (...SIGMA(K:1:25:4:...).

For arguments and results in radians, the conversion factor pi/180 should be used. Alternatively, the following set of equations (arguments and results in radians, but input range limited to [-pi..pi]) can be used:

SIN=2*SIGMA(K:1:21:4:X^K/FACT(K))-(EXP(X)-EXP(-X))/2
COS=2*SIGMA(K:0:20:4:X^K/FACT(K))-(EXP(X)+EXP(-X))/2
TAN=(4*SIGMA(K:1:21:4:X^K/FACT(K))-EXP(X)+EXP(-X))/(4*SIGMA(K:0:20:4:X^K/FACT(K))-EXP(X)-EXP(-X))
This latter set should work on all HP-17BII versions. I don't have any HP-17BII+ handy to test the first set of equations. Perhaps a few changes have to me made, because of issues with L() and G() on the newest models.

#2

The cos-cosh and sin-sinh series calculate the cos and sin values, respectively, with good accuracy. They are rivaled (as web searches recently reminded me) by their CORDIC versions for cos and sin. The CORDIC algorithms use pre-calculated tables of values to replace the rich list of polynomial coefficients used by summation series.

The moral of the proverbial story is ... if you need to calculate cos and sin (and other trig functions and their inverses) you need to work with sizable arrays of coefficients or tables. In other words, high-precision results come with a serious calculation effort. Using polynomials with 2 to 4 coefficients will generally not give you high precision results. You will get results that are good for a few decimal places. These limited results were acceptable in the days when the slide rule and log tables were kings and ruled the computational landscape! The advent of electronic calculators dethroned these vintage tools and made us expect high precision results.

Namir

#3

Namir,

Here is a very good reference, in case you are not aware of it yet:

http://www.research.scea.com/research/pdfs/RGREENfastermath_GDC02.pdf

http://www.research.scea.com/gdc2003/fast-math-functions_p1.pdf

http://www.research.scea.com/gdc2003/fast-math-functions_p2.pdf

BTW, here is the Minimax version of the radians sine equation (input range [-pi..pi]). The polynomial is four orders lower (that it, one term less), evaluated using Horner's Method. Also, there is only one instance of EXP, thus the the evaluation is very fast (about 0.7 seconds).

SIN=X*(2+L(Q:SQ(SQ(X)))*(1/60+G(Q)*(5.511463854E-6+G(Q)*(
3.211803895E-10+5.6307313E-15*G(Q)))))-(L(V:EXP(X))-1/G(V))/2

Regards,

Gerson.

--------------------

SUMMARY

MINIMAX EQUATIONS (RADIANS)

SIN=X*(2+L(Q:SQ(SQ(X)))*(1/60+G(Q)*(5.511463854E-6+G(Q)
*(3.211803895E-10+5.6307313E-15*G(Q)))))-(EXP(X)-EXP(-X))/2

COS=(L(V:SQRT(2)*(2+L(Q:SQ(SQ(X)))*(1/192+G(Q)*(
1.93762394E-7+1.01959E-12*G(Q)))-(EXP(X/2)+EXP(-X/2))/2))+1)*
(G(V)-1)

FULL RANGE TAYLOR SERIES EQUATIONS (DEGREES)

SIN=(1-2*IP((MOD(X:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:MOD(X:
180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)

COS=(1-2*IP((MOD(X+90:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:MOD(
X+90:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)

TAN=(4*SIGMA(K:1:21:4:(L(A:MOD(X:180)*PI/180))^K/FACT(K))-EXP
(G(A))+EXP(-G(A)))/(4*SIGMA(K:0:20:4:G(A)^K/FACT(K))-EXP(G(A))
-EXP(-G(A)))

FULL RANGE MINIMAX EQUATIONS (DEGREES)

SIN=(1-2*IP((MOD(X:360)/180)))*(L(A:MOD(X:180)*PI/180)*(2+L(
Q:SQ(SQ(G(A))))*(1/60+G(Q)*(5.511463854E-6+G(Q)*(
3.211803895E-10+5.6307313E-15*G(Q)))))-(EXP(G(A))-EXP(-G(A)))
/2)

COS=(1-2*IP((MOD(X+90:360)/180)))*(L(A:MOD(X+90:180)*PI/180)*
(2+L(Q:SQ(SQ(G(A))))*(1/60+G(Q)*(5.511463854E-6+G(Q)*(
3.211803895E-10+5.6307313E-15*G(Q)))))-(EXP(G(A))-EXP(-G(A)))
/2)

TAN=(L(A:MOD(X:180)*PI/180)*(2+L(Q:SQ(SQ(G(A))))*(1/60+G(Q)*(
5.511463854E-6+G(Q)*(3.211803895E-10+5.6307313E-15*G(Q)))))-(
EXP(G(A))-EXP(-G(A)))/2)/((L(V:SQRT(2)*(2+G(Q)*(1/192+G(Q)*(
1.93762394E-7+1.01959E-12*G(Q)))-(EXP(G(A)/2)+EXP(-G(A)/2))/
2))+1)*(G(V)-1))


Edited: 11 Apr 2013, 11:41 a.m.



Possibly Related Threads…
Thread Author Replies Views Last Post
  Solver issue with HP 17BII - different from 19BII Jeff Kearns 13 4,467 11-28-2013, 02:36 AM
Last Post: Don Shepherd
  17BII & 17BII+ Discounted Payback Period Revisited Tom Neudorfl 8 2,805 11-25-2013, 10:28 AM
Last Post: Don Shepherd
  HP Prime - CAS functions in Spreadsheet App CR Haeger 6 2,397 11-11-2013, 12:37 AM
Last Post: Michael de Estrada
  [41CL] New Extra Functions version Monte Dalrymple 0 1,084 11-08-2013, 04:32 PM
Last Post: Monte Dalrymple
  HP Prime: in need of help with defining functions Alberto Candel 14 4,184 10-27-2013, 10:48 AM
Last Post: Alberto Candel
  Is the Prime a superset of the HP 17bII+ ? vrrr 3 1,571 10-16-2013, 12:03 PM
Last Post: Michael de Estrada
  HP Prime spreadsheet functions SanS 0 1,875 10-04-2013, 04:23 AM
Last Post: SanS
  Stats functions on the HP34S Nicholas van Stigt 5 1,949 09-24-2013, 02:45 AM
Last Post: Nick_S
  Trig Functions Howard Owen 11 3,408 09-16-2013, 02:53 PM
Last Post: Fred Lusk
  50g piecewise functions Kurt Fankhauser 6 2,292 09-15-2013, 08:01 PM
Last Post: Kurt Fankhauser

Forum Jump: