The Museum of HP Calculators

HP Forum Archive 06

[ Return to Index | Top of Index ]

Improved TRIG. and INVERSE TRIG. functions for the HP-17BII
Message #1 Posted by W. B. Maguire II on 26 Sept 2001, 12:42 p.m.

Improved TRIG and INVERSE-TRIG functions for the HP-17BII

+------------------------------------------------------------------------------+
| If _anyone_ finds this post useful, please validate me with a response!  ;-) |
+------------------------------------------------------------------------------+

Background:

OK. I really like the HP-17BII. It has the great Pioneer dimensions. It has a nice, big 22-character display. It has dedicated soft-keys and a second line in the display for their labels. (I think I prefer this soft-key implementation to the 42's overloading of the soft-keys. I'll be in a menu and think I have access to those functions on the top row of keys. The dedicated soft keys [pioneered by the 28c/s] seem to be more intuitive to me.)

Anyway, being an engineer, I break out in a rash if I don't have access to the trigonometric and inverse-trig. functions.

So, to borrow from "Animal House":
I think that this situation absolutely requires a really futile and stupid gesture be done on somebody's part. And I'm just the guy to do it.

Several weeks ago, I posted my routines for calculating the TRIG. and INVERSE TRIG. functions. Unfortunately, I didn't realize that the factorial function existed on the 17BII! Duh! I also did not know about the undocumented "L()" and "G()" (Let and Get) functions. I strongly encourage anyone who would like to program the 17BII to buy the CD-ROMs from the HP Museum in order to obtain the "Technical Applications" book for the 27S and 19B. The undocumented "Let" and "Get" functions are described, as well as methods of executing looping---these functions open-up programming options that were not conceivable before! For instance: definite loops and invisible, temporary variable assignments. Definitely a MUST READ! By the way, in my opinion, these functions completely put to rest the question of whether the 17BII and 19BII are "programmable"---they absolutely are!

So, anyway, here is my self-redemption for those embarassing, brute-force routines.

Equation Descriptions:

The following equations for the HP-17BII calculate the TRIG. and INVERSE TRIG. functions. I originally had larger formulas that combined SIN,COS,TAN into one equation, and ASIN,ACOS,ATAN into one equation. But, I wanted to minimize the "CALC" time for these formulas, since it's just overhead. As a result, I have left out the TAN function, because it is very easy to enter the angle, press [SIN] then [COS] then the divide key. Since ASIN and ACOS are so similar, they are in one equation, but ATAN is just different enough to (in my mind) justify a seperate equation.

Another approach---which I still might consider---is to cram all desired functions into one single equation, and then try not to leave the solve menu. Getting back into the solve menu would take literally minutes of "CALC" time!

In the interest of accuracy, the inverse trig. functions are divided into multiple domains, so that the polynomials converge faster. The ASIN and ACOS have two domains: [0,PI/4] and [PI/4,PI/2]. The ATAN is a little more complicated; its domains are: [0,~0.3927], [~0.3927,~1.1781], and [~1.1781,inf). The accuracy for the ATAN function is MUCH better than a tangent Taylor series approximation (and therefore MUCH faster). After the routine listings, I have computed (using Matlab) the worst-case accuracy of the equations, given various maximum-exponent values (in the polynomial series).

In the following equations: "SIGMA" means the sigma symbol:

   (In the ALPHA menu: 
   [WXYZ][OTHER][MORE], 
   then the second button)
"ANGLE" means the angle symbol:
   (In the ALPHA menu: 
   [WXYZ][OTHER][MORE][MORE][MORE][MORE],
   then the fifth button)
The formula for the SIN and COS was kindly supplied by Kynes.

Equation Listings:

DEGREES~RADIANS:
   DEG/180*PI=RAD

SIN,COS,D~R: IF(S(SIN): SIGMA(N:0:9:1:(-1)^N* ANGLE^(2*N+1)/FACT(2N+1))-SIN : IF (S(COS): SIGMA(N:0:9:1:(-1)^N* ANGLE^(2*N)/FACT(2N))-COS : DEG/180*PI-RAD ) )

ASIN,ACOS,D~R: IF(NOT (S(DEG) OR S(RAD)): 0* IF(X<.7071: L(R3:X)+ IF(S(ASIN): L(R1:0)+L(R2:1) : L(R1=1)+L(R2=-1) ) : L(R3:SQRT(1-SQ(X)))+ IF(S(ASIN): L(R1=1)+L(R2=-1) : L(R1:0)+L(R2:1) ) ) +G(R1)*PI/2+G(R2)*( G(R3)+ SIGMA(N:3:31:2: (FACT(N-2)*(G(R3))^N/ (2^(N-2)*FACT((N-3)/2)*FACT((N-1)/2)*N))) ) - IF(S(ASIN): ASIN : ACOS ) : DEG/180*PI-RAD )

ATAN,D~R: IF(NOT (S(DEG) OR S(RAD)): 0* IF(L(AA:ABS(SQ(X)-1)/(SQ(X)+1))<.7071: L(R1:.5)+ L(R2:SGN(X-1)/2)+ L(R3:G(AA)) : L(R1:.5+SGN(X-1)/2)+ L(R2:.5-G(R1))+ L(R3:2*X/(SQ(X)+1)) ) +G(R1)*PI/2+G(R2)*( G(R3)+ SIGMA(N:3:31:2: (FACT(N-2)*(G(R3))^N/ (2^(N-2)*FACT((N-3)/2)*FACT((N-1)/2)*N))) ) -ATAN : DEG/180*PI-RAD )

Sample Calculations:

Sin(30 degrees):
"CALC" the SIN,COS equation, then press:

30[DEG][RAD][STO][angle-key][SIN]
Answer = 0.5000
---------------------------------

Tan(45 degrees):
"CALC" the SIN,COS equation, then press:

45[DEG][RAD][STO][angle-key][SIN][COS][divide-key]
Answer = 1.0000
---------------------------------

ArcSin(0.5):
"CALC" the ASIN,ACOS equation, then press:

0.5[X][ASIN]
Answer = 0.5236 radians
To get the answer in degrees, press:
[STO][RAD][DEG]
Answer = 30.000 degrees
---------------------------------

The ArcTan function works the same as the ArcSin and ArcCos, but you need to "CALC" the ATAN equation, rather than the ASIN,ACOS equation.

Accuracy Calculations:

For the following accuracy calculations, Matlab was used. Therefore the following accuracies are closer to the theoretical accuracy of the previous algorithms. 'Epsilon'---in the computational context---means the smallest number (in a computer) that may be added to one, and yield a result that is greater than one. It is a measure of the precision that the computer uses to represent numbers (really the number of bits for the mantissa). The Epsilon for the HP-17BII is about 5e-12. (I presented an equation to show this for the HP-17BII in a separate posting.) The Epsilon for Matlab is about 2e-16. Therefore, the HP-17BII will not be any more accurate than 5e-12 in the best case (not O(10^-16) as indicated in some cases below).

For the SIN,COS equation (COS accuracy is the same as SIN):
-----------------------------------------------------------
Highest exponent of  5, gives maximum normalized     SIN error of 5.62e-08
Highest exponent of  7, gives maximum normalized     SIN error of 6.02e-12
Highest exponent of  9, gives maximum normalized     SIN error of 5.55e-16
Highest exponent of 11, gives maximum normalized     SIN error of 5.41e-16

Highest exponent of 5, gives maximum normalized SIN/COS error of 4.84e-03 Highest exponent of 7, gives maximum normalized SIN/COS error of 6.76e-07 Highest exponent of 9, gives maximum normalized SIN/COS error of 3.67e-11 Highest exponent of 11, gives maximum normalized SIN/COS error of 1.21e-12

For the ASIN equation (ACOS accuracy is the same as ASIN): ---------------------------------------------------------- Highest exponent of 15, gives maximum normalized ASIN error of 7.10e-05 Highest exponent of 17, gives maximum normalized ASIN error of 3.03e-05 Highest exponent of 19, gives maximum normalized ASIN error of 1.32e-05 Highest exponent of 21, gives maximum normalized ASIN error of 5.78e-06 Highest exponent of 23, gives maximum normalized ASIN error of 2.57e-06 Highest exponent of 25, gives maximum normalized ASIN error of 1.15e-06 Highest exponent of 27, gives maximum normalized ASIN error of 5.19e-07 Highest exponent of 29, gives maximum normalized ASIN error of 2.36e-07 Highest exponent of 31, gives maximum normalized ASIN error of 1.08e-07 Highest exponent of 33, gives maximum normalized ASIN error of 4.95e-08 Highest exponent of 35, gives maximum normalized ASIN error of 2.29e-08 Highest exponent of 37, gives maximum normalized ASIN error of 1.06e-08 Highest exponent of 39, gives maximum normalized ASIN error of 4.92e-09 Highest exponent of 41, gives maximum normalized ASIN error of 2.30e-09

Accuracy for ATAN in the ATAN equation is the same as ASIN and ACOS.

Now, all the HP-17BII needs is an "Engineering" display mode!

Bruce.

      
Re: Improved TRIG. and INVERSE TRIG. functions for the HP-17BII
Message #2 Posted by Frank Travis on 26 Sept 2001, 1:26 p.m.,
in response to message #1 by W. B. Maguire II

A good source of information on using the HP17BII and HP19BII (that go even beyond the user's manuals that they came with) are:

An Easy Course in Using the HP17BII

An Easy Course is Using the HP19BII

They can be obtained from Calcpro website www.calcpro.com. I have purchased from Calcpro several times and have had good dealings with its manager, Paul Nelson.

      
Re: Try using an HP48GX/G+ for engineering related uses
Message #3 Posted by Frank Travis on 26 Sept 2001, 2:11 p.m.,
in response to message #1 by W. B. Maguire II

You might want to consider using an HP48GX or HP48G+ calculator for engineering related applications. Calcpro website www.calcpro.com has these calculators and a line of books and accessories for the HP48GX and HP48G+. I own and use an HP48GX and an HP48G (w/only 32K RAM, replaced by the HP48G+ w/ 128K RAM) and have made purchases from Calcpro and talked to their manager, Paul Nelson, several times.

            
Re: Try using an HP48GX/G+ for engineering related uses
Message #4 Posted by W. B. Maguire II on 26 Sept 2001, 3:49 p.m.,
in response to message #3 by Frank Travis

Frank:

I appreciate the feedback.

I own a 48s. It is perhaps my least-favorite HP. First of all, it is just WAY to big to carry around. Second, although the screens have been improved, I still find the display hard to read (optimized for graphics?). Third, it is complex enough that you either have to use it all the time (to be very familiar with it), or just know that you won't be able to program it---and otherwise take advantage of its power. I know that sounds stupid, but that's just my own feeling. All in all, the 48 just feels like a small computer, rather than an easily-programmable calculator.

Personally, I love my HP-17BII. And at this point, I feel it is easier to program than anything. If it weren't for the clamshell design (which can't be comfortably hand-held), I'd probably still be using my HP-28S and it would be my favorite. The HP-42S seems to be a good compromise, but I still prefer the dedicated soft keys and variable-oriented solvers of the 17BII and 28S.

Bruce.

                  
Re: Try using an HP48GX/G+ for engineering related uses
Message #5 Posted by Ellis Easley on 3 Oct 2001, 11:26 a.m.,
in response to message #4 by W. B. Maguire II

I share your view on the 48 and I have heard it expressed by a number of people. In my case, I'm probably not smart enough to be able to take advantage of what it can provide, although, being not-smart, I just think it has too many buttons! But it will always be on my list of things to do, to learn how to use it effectively. Sometimes I think if I had been in college when it came out I might have picked it right up for one reason: time.

You have piqued my curiosity and now I must get a 17BII! I have a favorite 12C which I found lying in the street, in pieces, which is usually closest to hand when I need to do a quick calculation.

                        
Re: Getting an HP17BII
Message #6 Posted by Frank Travis on 3 Oct 2001, 12:02 p.m.,
in response to message #5 by Ellis Easley

I am happy with my HP17BII. A good place to buy HP calculators, supplemental books, and accessories is Calcpro website www.calcpro.com. I have purchased from Calcpro several times and have talked on many occasions to their manager, Paul Nelson. A good book to supplement your understanding of the HP17BII is An Easy Course in Using the HP17BII. Calcpro should have it. Good Luck!

                              
Re: Getting an HP17BII
Message #7 Posted by Ellis Easley on 3 Oct 2001, 12:12 p.m.,
in response to message #6 by Frank Travis

Thanks, Frank. Who would you recommend I talk to when I go to Calcpro.com?

Just kidding.

                                    
Re: Getting an HP17BII
Message #8 Posted by Frank Travis on 3 Oct 2001, 12:35 p.m.,
in response to message #7 by Ellis Easley

Paul Nelson, if available. Else one of his helpers.

                        
Re: Try using an HP48GX/G+ for engineering related uses
Message #9 Posted by W. Bruce Maguire II on 3 Oct 2001, 4:20 p.m.,
in response to message #5 by Ellis Easley

Ellis:

Definitely do yourself a favor, and get a 17BII! I think it is a really great machine. BTW, there is also a large supply of 17BIIs being sold on eBay---many of them new-in-box.

I have also purchased two HPs from a store called Comox Valley Computers Ltd. One was an auction on eBay, and one was by calling the store directly. Their eBay ID is "q-test". I don't believe they have anything up for auction now, but you should call Leslie at 1-250-338-0727 (Monday through Saturday 9 AM to 5 PM Pacific Time) and ask her for a good price on a 17BII. ;-)

Be sure to look on the Museum CD for that 27s/19b manual (I think that's what it is...) that talks about the L() and G() functions, and don't overlook the S() function which is only briefly mentioned in the 17BII manual in the 'solver' section.

Bruce.

      
Re: Improved TRIG. and INVERSE TRIG. functions for the HP-17BII
Message #10 Posted by David Smith on 26 Sept 2001, 5:46 p.m.,
in response to message #1 by W. B. Maguire II

Actually these series expansions for sin, cos, etc are not very good for real world applications. For values outside the first quadrant they become rather inaccurate tarher fast... try doing the sin of 360 degrees, etc.

Also, for maximum accuracy you should calculate the sin and cos values from the tangent function. HP published a very good description of the internal algorithms for the 9100 series calculators. I beleive at least part of it is in the HPMUSEUM section on the 9100A (or in the Journal articles).

            
Re: Improved TRIG. and INVERSE TRIG. functions for the HP-17BII
Message #11 Posted by W. B. Maguire II on 26 Sept 2001, 9:54 p.m.,
in response to message #10 by David Smith

David:

Yes, you are correct. I failed to mention that I only intended to solve the problem in the first quadrant. But I did mention that the ASIN function is solved differently in the two different regimes [0,pi/4] and [pi/4,pi/2]. Personally, that's all I need, as all other quadrants trivially map to the first quadrant with a rotation through pi/2 or pi (that's easy enough for me to do mentally). And all these functions are accurate enough in the first quadrant for my purposes.

I also hadn't seen any other solutions posted here for the inverse trig functions on the 17BII.

If I were writing trig. functions that would be evaluated by other functions, then obviously what I did here is an incomplete solution.

If you have better trig. and inverse trig. function equations for the 17BII, please post them. I would quickly adopt anyone's solution that "CALC"ed and evaluated more quickly than the ones I have presented.

Bruce.

                  
Re: Improved TRIG. and INVERSE TRIG. functions for the HP-17BII
Message #12 Posted by Michael Blankenship on 16 Oct 2001, 11:19 a.m.,
in response to message #11 by W. B. Maguire II

All,

I have posted what I feel are better trig functions back in Forum Archive 6, see "Add trig functions on HP17BII, etc.? (You can)" for the source. The SIN and other trig functions can be accurately converted into a power series using calculus. The HP's summation notation works nicely and with a surprising few characters. In my post I've described how to adjust the accuracy to your taste using more decimal places and more iteration in the power series. I am confident that this approach will always yield fast, accurate results.

FYI and good luck, M.

                        
WHAT are you talking about?!?
Message #13 Posted by W. Bruce Maguire II on 16 Oct 2001, 1:27 p.m.,
in response to message #12 by Michael Blankenship

All,

I have posted what I feel are better trig functions back in Forum Archive 6, see "Add trig functions on HP17BII, etc.? (You can)" for the source. The SIN and other trig functions can be accurately converted into a power series using calculus. The HP's summation notation works nicely and with a surprising few characters. In my post I've described how to adjust the accuracy to your taste using more decimal places and more iteration in the power series. I am confident that this approach will always yield fast, accurate results.

FYI and good luck, M.

Mike:

Did you even look at my post?

Your COS equation:

COS=1+SIGMA(I:2:12:2:((MOD(I/2:2)x-2)+1)x(THETA^I)/FACT(I))

My COS equation:

   SIGMA(N:0:9:1:(-1)^N*ANGLE^(2*N)/FACT(2N))-COS

Extracted from the original---whole---equation:

SIN,COS,D~R:
   IF(S(SIN):
      SIGMA(N:0:9:1:(-1)^N*
      ANGLE^(2*N+1)/FACT(2N+1))-SIN
   :
      IF (S(COS):
         SIGMA(N:0:9:1:(-1)^N*
         ANGLE^(2*N)/FACT(2N))-COS
      :
         DEG/180*PI-RAD
      )
   )

What, exactly, do feel is superior about your equation?

In my post I've described how to adjust the accuracy to your taste using more decimal places and more iteration in the power series

Um, I think I discussed accuracy in great detail at the bottom of my post, by changing the number of terms in the summations. And, changing the number of decimal places in the display does not change the accuracy, as you imply.

Also, I did not notice the INVERSE trig. functions in your post. Those are not exactly esoteric functions, they are often necessary when doing trig. work.

All in all, I believe that my posted solution was just fine (as it was really another implementation of the same solution methodology using series approximations for the basic trig. functions). I disagree with your assertion, "I have posted what I feel are better trig functions..." Before you knock someone's posted solution, I think that you ought to be sure that you know what you are talking about.

Bruce.

      
Re: Improved TRIG. and INVERSE TRIG. functions for the HP-17BII
Message #14 Posted by r. w. smith on 1 Oct 2001, 11:34 p.m.,
in response to message #1 by W. B. Maguire II

This should go into the HPmuseum archive! Dave?


[ Return to Index | Top of Index ]

Go back to the main exhibit hall