The Museum of HP Calculators

HP Forum Archive 16

[ Return to Index | Top of Index ]

HP-17BII - trig equations suggestions
Message #1 Posted by Gerson W. Barbosa on 30 Dec 2006, 5:49 p.m.

Two weeks ago I got an unused HP-17BII from a zero-feedback local seller. No blister case, but it came with a shrink-wrapped manual in English, which of course I have already opened. All for less than $55, shipping included. Not a big deal, but here they typically sell for twice this price. If I only could find an HP-42S like that...

I tried W. B. Maguire's Improved TRIG. and INVERSE TRIG. functions for the HP-17BII . I tested both his sine and cosine functions. They work nicely, only the running time is about 1.9 seconds, not bad but too long when compared to the instant answers we get on the HP-42S.

As I got curious to know how a polynomial approximation would perform on the HP-17BII Solver I tried the equation below. The running time dropped to about 0.7 seconds. Actually, I should have replaced the Taylor's series in the original equation with mine and check how it would behave. Anyway, the polynomial approximation approach appears to be more tailored to this task than the Taylor's Series, regarding speed (no pun intended :-) I haven't tested the inverse functions, but I guess the gain in speed would be more significant.

SIN=L(SX:X*(5.8177641733
1E-3+L(X2:SQ(X))*(-3.281
8376137E-8+G(X2)*(5.5539
1606E-14+G(X2)*(2.0935E-
26*G(X2)-4.47566E-20))))
)*(3-4*SQ(G(SX)))

Some examples:

Sin(x): 

x (deg) HP-17BII HP-42S -------------------------------------------------- 0.000000 0.00000000000E+00 0.00000000000E+00 0.000001 1.74532925199E-08 1.74532925199E-08 0.000110 1.91986217719E-06 1.91986217719E-06 0.022000 3.83972426002E-04 3.83972426004E-04 3.330000 5.80867495978E-02 5.80867495977E-02 14.44000 2.49366025115E-01 2.49366025115E-01 25.55000 4.31298587031E-01 4.31298587031E-01 30.00000 5.00000000000E-01 5.00000000000E-01 36.66000 5.97065256389E-01 5.97065256389E-01 47.77000 7.40452782677E-01 7.40452782677E-01 58.88000 8.56086728293E-01 8.56086728292E-01 69.99000 9.39632912698E-01 9.39632912698E-01 81.11000 9.87986852775E-01 9.87986852778E-01 88.88000 9.99808950038E-01 9.99808950038E-01 89.99900 9.99999999848E-01 9.99999999848E-01 89.99990 9.99999999998E-01 9.99999999998E-01 90.00000 1.00000000000E+00 1.00000000000E+00

The input range is [-90..90]. The maximum absolute error in this equation is 5.8E-14. The difference of up to three units in the last significant digit are due to rounding errors.

It's interesting to notice this simple sine equation allows for the computation of all six functions. The inverse sine function can be solved iteratively:

For instance, let's compute asin(0.77):

45  [X]        ; first estimate
.77 [SIN]
[X]            =>  X=50.3538888531 
This almost matches the HP-42S answer: 50.353888853

The remaining functions can be computed using trigonometric identities:

cos(x) = sin(90 - x);

tan(x) = sin(x)/cos(x);

acos(x) = asin(sqrt(1-x^2), acos(x) = 90 - asin(x);

atan(x) = asin(x/sqrt(1+x^2))

The atan(x) equation below is accurate in the range [-(2-sqrt(3))..(2-sqrt(3))] (max absolute error = 6.4E-14):

ATAN=X*(1+L(X2:SQ(X))*(-
0.33333333333+G(X2)*(0.1
9999999631+G(X2)*(-0.142
8565387+G(X2)*(0.1110748
114+G(X2)*(0.0641264*G(X
2)-0.08991517))))))*57.2
957795131

As we have seen, the lack of trigonometric functions on the HP-17BII was solved brilliantly years ago. Anyway, I hope these equations might be useful to anyone who wants to get back to the subject.

Gerson.

      
Re: HP-17BII - trig equations suggestions
Message #2 Posted by Bob Wang on 30 Dec 2006, 7:50 p.m.,
in response to message #1 by Gerson W. Barbosa

Very, very nice. That's a keeper.

Thanks, Gerson.

Bob

            
Re: HP-17BII - trig equations suggestions
Message #3 Posted by Gerson W. Barbosa on 30 Dec 2006, 8:42 p.m.,
in response to message #2 by Bob Wang

Hi Bob,

Thanks for your interest. Please refer to article #654 for formulas to expand the range of the atan(x) function (formulas iii and iv, scrolling down next to the end of the page). My knowlege of the HP-17BII solver is very limited, you won't have trouble making the required changes though. It would also be interesting to assure it works also on the HP-17BII+, as I am aware there are some slight compatibility issues between these models.

Best regards,

Gerson.

                  
Re: HP-17BII - trig equations suggestions
Message #4 Posted by Charles on 1 Jan 2007, 7:15 p.m.,
in response to message #3 by Gerson W. Barbosa

Gerson,

I think that this is a really excellent piece of work- well done.

As you suggested, I have tried the cos with the sin(90-x) equation and it works really well as does tan(x)=sin(x)/cos(x). Arctan also works with the same equation and the solver. This work is well worth putting on the site archives.

I have listed the full set of equations for those not used to the HP 17BII as well as a comparison with the 32SII (to 9 significant figures). I should also mention that I have changed X to DEG.

SIN=L(SX:DEG*(5.8177641733 1E-3+L(X2:SQ(DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX)))

COS=L(SX:(90-DEG)*(5.8177641733 1E-3+L(X2:SQ(90-DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX)))

TAN=(L(SX:DEG*(5.8177641733 1E-3+L(X2:SQ(DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX))))/( L(SX:(90-DEG)*(5.8177641733 1E-3+L(X2:SQ(90-DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX))))

Sin Cos Deg HP17BII 32SII HP17BII 32SII 0 0.000000000 0.000000000 1.000000000 1.000000000 30 0.500000000 0.500000000 0.866025404 0.866025404 45 0.707106781 0.707106781 0.707106781 0.707106781 60 0.866025404 0.866025404 0.500000000 0.500000000 80 0.984807753 0.984807753 0.173648178 0.173648178 85 0.996194698 0.996194698 0.087155743 0.087155743 89 0.999847695 0.999847695 0.017452406 0.017452406 89.5 0.999961923 0.999961923 0.008726535 0.008726535 89.9 0.999998477 0.999998477 0.001745328 0.001745328

average 0.000000 0.000000 error

Tan Deg HP17BII 32SII 0 0.000000000 0.000000000 30 0.577350269 0.577350269 45 1.000000000 1.000000000 60 1.732050808 1.732050808 80 5.671281820 5.671281820 85 11.43005230 11.43005230 89 57.2899616 57.2899616 89.5 114.5886501 114.5886501 89.9 572.9572134 572.9572134

average 0.000000 error

                  
Re: HP-17BII - trig equations suggestions
Message #5 Posted by Charles on 1 Jan 2007, 7:16 p.m.,
in response to message #3 by Gerson W. Barbosa

Gerson,

I think that this is a really excellent piece of work- well done.

As you suggested, I have tried the cos with the sin(90-x) equation and it works really well as does tan(x)=sin(x)/cos(x). Arctan also works with the same equation and the solver. This work is well worth putting on the site archives.

I have listed the full set of equations for those not used to the HP 17BII as well as a comparison with the 32SII (to 9 significant figures). I should also mention that I have changed X to DEG.

SIN=L(SX:DEG*(5.8177641733 1E-3+L(X2:SQ(DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX)))

COS=L(SX:(90-DEG)*(5.8177641733 1E-3+L(X2:SQ(90-DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX)))

TAN=(L(SX:DEG*(5.8177641733 1E-3+L(X2:SQ(DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX))))/( L(SX:(90-DEG)*(5.8177641733 1E-3+L(X2:SQ(90-DEG))*(-3.281 8376137E-8+G(X2)*(5.5539 1606E-14+G(X2)*(2.0935E- 26*G(X2)-4.47566E-20)))) )*(3-4*SQ(G(SX))))

Sin Cos Deg HP17BII 32SII HP17BII 32SII 0 0.000000000 0.000000000 1.000000000 1.000000000 30 0.500000000 0.500000000 0.866025404 0.866025404 45 0.707106781 0.707106781 0.707106781 0.707106781 60 0.866025404 0.866025404 0.500000000 0.500000000 80 0.984807753 0.984807753 0.173648178 0.173648178 85 0.996194698 0.996194698 0.087155743 0.087155743 89 0.999847695 0.999847695 0.017452406 0.017452406 89.5 0.999961923 0.999961923 0.008726535 0.008726535 89.9 0.999998477 0.999998477 0.001745328 0.001745328

average 0.000000 0.000000 error

Tan Deg HP17BII 32SII 0 0.000000000 0.000000000 30 0.577350269 0.577350269 45 1.000000000 1.000000000 60 1.732050808 1.732050808 80 5.671281820 5.671281820 85 11.43005230 11.43005230 89 57.2899616 57.2899616 89.5 114.5886501 114.5886501 89.9 572.9572134 572.9572134

average 0.000000 error

REPLACE THIS TEXT WITH YOUR LISTING
                        
Re: HP-17BII - trig equations suggestions
Message #6 Posted by Gerson W. Barbosa on 1 Jan 2007, 9:22 p.m.,
in response to message #5 by Charles

Hi Charles,

Thanks for your efforts so far. As I said, I have only suggested the basic equations, which are based on Minimax Polynomial Approximations. This is the same technique used in the HP-12C Platinum program.

Quote:
Arctan also works with the same equation and the solver.

The problem is that this way the inverse functions are solved iteratively, which is slow and sometimes may require a good estimate to give the correct answer. The idea is obtaining a set of equations that allows all six functions to be computed quickly (1.5 seconds or less) and accurately (at least 11 significant digits), in the ranges [-360..360] degrees (or at least [-90..90]) (SIN, COS and TAN], [-1..1] (ASIN, ACOS), and [-9.99E-249..9.99E249] (ATAN). I think this is possible using the formulas used in the HP-12C Platinum program and advanced solver techniques, described in the Technical Application book for the HP-27S and HP-19B (available in the Museum DVD), as mentioned in Maguire's article.

Just a tip:

 [pre]

insert your text between these delimeters to let it formatted the way you want it.

[\pre]

More details here:

advanced formatting techniques

Regards,

Gerson.

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

P.S.: I checked your COS and TAN equations on the HP-200LX solver (where they are easier to enter and edit) and they work, despite these shortcomings:

1) As already mentioned, the inverse functions can be solved only iteratively, which means rather time consuming calculations;

2) The full-accuracy ranges are [0..180] for COS and [-90..90] for SIN. Therefore the range for TAN is [0..90]. And ATAN will accurate only for positive arguments. For instance, atan(10000) returns 89.9942704221, which is correct, and atan(-10000) returns -89.9942623047, which is not.

They can be useful for occasional calculations though.

Here are your formatted tables (kind of):

Sin Cos

Deg HP17BII 32SII HP17BII 32SII 0 0.000000000 0.000000000 1.000000000 1.000000000 30 0.500000000 0.500000000 0.866025404 0.866025404 45 0.707106781 0.707106781 0.707106781 0.707106781 60 0.866025404 0.866025404 0.500000000 0.500000000 80 0.984807753 0.984807753 0.173648178 0.173648178 85 0.996194698 0.996194698 0.087155743 0.087155743 89 0.999847695 0.999847695 0.017452406 0.017452406 89.5 0.999961923 0.999961923 0.008726535 0.008726535 89.9 0.999998477 0.999998477 0.001745328 0.001745328

average 0.000000 0.000000 error

Tan

Deg HP17BII 32SII 0 0.000000000 0.000000000 30 0.577350269 0.577350269 45 1.000000000 1.000000000 60 1.732050808 1.732050808 80 5.671281820 5.671281820 85 11.43005230 11.43005230 89 57.2899616 57.2899616 89.5 114.5886501 114.5886501 89.9 572.9572134 572.9572134

average 0.000000 error

Edited: 2 Jan 2007, 11:00 a.m.

                              
Re: HP-17BII - trig equations suggestions
Message #7 Posted by Charles on 2 Jan 2007, 6:08 p.m.,
in response to message #6 by Gerson W. Barbosa

Gerson,

Thanks for sorting out the formatting.

I should explain why I like the programme so much. I bought the HP17BII cheaply a few years ago and use it when I travel on business. I don't use trigonometric functions often but do sometimes so they are handy to have. When I do, I've probably read a dimension from a drawing or used a protractor so accuracy isn't critical. I'm old enough to have used a slide rule so I'm quite happy to have something where I need to put in the pluses and minuses.

The programme Bruce Maguire wrote is very good (I have a plasticised copy in my calculator case)but occasionally the batteries appear to become loose and I lose memory. Your programme is simpler, easier to type in and fits my needs.

Regards Charles

                                    
Re: HP-17BII - trig equations suggestions
Message #8 Posted by Gerson W. Barbosa on 3 Jan 2007, 10:43 a.m.,
in response to message #7 by Charles

Hello Charles,

On second thought I see you are right. There is no need to complicate the equations. As of the accuracy, it is quite fine if we stick to the ranges where full accuracy is granted.

I keyed the equations into my HP-17BII. To tell you the truth I didn't like to key in the long TAN equation. Anyway, some simplification attempts resulted in a longer equation.

The table below is a demonstration of both the accuracy and easy of use of the equations in the HP-17BII Solver. In my calculator they are ordered as SIN, COS, TAN.

-------------------------------------------------------------------------------------------------
         Keystrokes                        Display                       Calculation
-------------------------------------------------------------------------------------------------
9 [X] [SIN]                          SIN=0.15643446504                      sin(9)      
[EXIT] [v] [CALC] [STO] [X] [COS]    COS=9.99996272745E-1                 cos(sin(9))
[EXIT] [v] [CALC] [STO] [X] [TAN]    TAN=1.74549998555E-2               tan(cos(sin(9)))	
[STO] [TAN] [X]       	               X=9.99996272745E-1            atan(tan(cos(sin(9))))  	
[EXIT] [^] [CALC] [STO] [COS] [X]      X=1.56434385713E-1         acos(atan(tan(cos(sin(9))))) 	
[EXIT] [^] [CALC] [STO] [SIN] [X]      X=8.99999539825         asin(acos(atan(tan(cos(sin(9))))))  
-------------------------------------------------------------------------------------------------

This is Mike Sebastian's forensic result for this set of equations. As a comparison, on the HP-32SII the result is 8.99999864267.

Quote:
Your programme is simpler, easier to type in and fits my needs.

I think we can say our program since you've worked out the COS and TAN equations :-) I don't use the HP-17BII on a regular basis, but these would certainly fit my needs. Thanks!

Best regards,

Gerson.

Edited: 3 Jan 2007, 10:52 a.m.

                                          
Re: HP-17BII - trig equations suggestions
Message #9 Posted by Charles on 3 Jan 2007, 5:02 p.m.,
in response to message #8 by Gerson W. Barbosa

Gerson,

Thanks for the compliment but you did all the hard work ! My contribution was minor.

The forsenic test result is interesting. If you take the differences between 9 and the final number then multiply by 1e6, you get:

HP17BII 4.6 HP32SII 1.3 HP15C/41C 417

Pretty good !

                                                
Re: HP-17BII - trig equations suggestions
Message #10 Posted by Gerson W. Barbosa on 3 Jan 2007, 5:43 p.m.,
in response to message #9 by Charles

There was an interesting thread started by Rodger Rosenbaum recently involving accuracy features in HP calculators I was not aware of. Perhaps you'd like to take a look at it:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv016.cgi?read=103151

The topic was continued later:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv016.cgi?read=103356

Best regards,

Gerson.

      
Re: HP-17BII - trig equations suggestions
Message #11 Posted by bill platt on 3 Jan 2007, 8:41 p.m.,
in response to message #1 by Gerson W. Barbosa

Gerson and Charles,

Thank you very much for this thread! I somehow missed it until now. Great stuff that is worth going into the Articles eventually I think.

Regards,

Bill


[ Return to Index | Top of Index ]

Go back to the main exhibit hall