Mardi Gras Basic Trigs (HP-12C)



#2

01-   2	                21-   +
02- / 22- 2
03- ENTER 23- /
04- ENTER 24- -
05- 4 25- 2
06- y^x 26- +
07- 12/ 27- ENTER
08- ENTER 28- *
09- ENTER 29- 2
10- 1 30- *
11- 4 31- 1
12- 0 32- -
13- / 33- ENTER
14- 1 34- ENTER
15- + 35- ENTER
16- * 36- *
17- x<>y 37- CHS
18- e^x 38- 1
19- ENTER 39- +
20- 1/x 40- SQRT
41- GTO 00

Usage:

Enter angle in radians ( 0 <= x <= pi/2 )

R/S -> sin(x)

x<>y -> cos(x)

/ -> tan(x)

Examples:

x | sin(x) | cos(x) | tan(x) |
------+-------------+-------------+-------------+
1.57 | 0.999999683 | 0.000796323 | 1255.771443 |
1.50 | 0.997494987 | 0.070737199 | 14.10142048 |
1.00 | 0.841470987 | 0.540302303 | 1.557407736 |
0.50 | 0.479425537 | 0.877582563 | 0.546302487 |
0.00 | 0.000000000 | 1.000000000 | 0.000000000 |

x |sin(x*pi/180)|cos(x*pi/180)|tan(x*pi/180)|
------+-------------+-------------+-------------+
90.0 | 1.000000000 |-0.000000003*|-294117647.1*|
89.9 | 0.999998477 | 0.001745329 | 572.9570052 |
60.0 | 0.866025403 | 0.500000001 | 1.732050803 |
45.0 | 0.707106783 | 0.707106779 | 1.000000006 |
30.0 | 0.500000001 | 0.866025403 | 0.577350271 |


*) wrong sign for cos(90 degrees);
invalid result for tan(90 degrees).

pi/180 = 1.745329252e-02


Warnings: 1) not suitable for geodesic applications, space program, land surveying and other critical applications.
2) tan(89.999999) is a bit off: 62,500,000.00 :-)


#3

But you said that you enter the angle in radians so an angle of 89.999999 should yield you -1.99520539304 which still isn't close to "your" implied 62,500,000.00. ;-)


#4

I should have written tan(89.999999 degrees), sorry! Angles in degrees have to be converted to radians, like in the second table examples, which have been multiplied by 1.745329252e-02, that is, pi/180.
I forgot to mention the running time, less than five seconds (ordinary HP-12C). Also, the program gives at least eight digits of accuracy most of the times.

Regards,

Gerson.

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

The HP-12c Platinum should give more accurate results, but I don't have one to check this out.


Edited: 8 Mar 2011, 3:33 p.m.


#5

Gerson, can you give some background on the formulas used?


#6

Hi Marcus,

Sorry for the lack of documentation. I hope the following is clear. Basically, I combined cos(x) and cosh(x) and used my HP-28S to obtain the required Taylor series.

Regards,

Gerson.

3:          'COS(X)'
2: 'X'
1: 8

TAYLR => '1-.5*X^2+
4.16666666667E-2*X^4
-1.38888888889E-3*X^
6+2.48015873016E-5*X
^8'


3: 'COSH(X)'
2: 'X'
1: 8

TAYLR => '1+.5*X^2+
4.16666666667E-2*X^4
+1.38888888889E-3*X^
6+2.48015873016E-5*X
^8'

+ => '1-.5*X^2+
4.16666666667E-2*X^4
-1.38888888889E-3*X^
6+2.48015873016E-5*X
^8+
(1+.5*X^2+
4.16666666667E-2*X^4
+1.38888888889E-3*X^
6+2.48015873016E-5*X
^8)'

COLCT => '2+8.33333333334E-2*
X^4+4.96031746032E-5
*X^8'


That is,

cos(x) ~ 2 + x^4/12 + x^8/20160 - cosh(x),

which has been rewritten as

cos(x) ~ 2 + x^4/12(1 + x^4/12/140) - (e^x + 1/e^x)/2

This provides 9 digits of accuracy or so for |x|<=pi/4. So, the argument is first divided by 2
then a trigonometric identity is used:

cos(x) = 2*(cos(x/2))^2 -1

Finally, sin(x) is computed as

sin(x) = sqrt(1 - cos(x)^2)


The tables below give an idea of the overall accuracy.

An HP-32S-II has been used to simulate the hp-12c platinum results in the table below, so they may differ a little.


hp-12c platinum

x | sin(x) | cos(x) | tan(x) |
------+-------------+-------------+-------------+
1.57 | 0.999999683 | 0.000796326 | 1255.766602 |
1.50 | 0.997494987 | 0.070737201 | 14.10142002 |
1.00 | 0.841470985 | 0.540302306 | 1.557407725 |
0.50 | 0.479425539 | 0.877582562 | 0.546302490 |
0.00 | 0.000000000 | 1.000000000 | 0.000000000 |


x |sin(x*pi/180)|cos(x*pi/180)|tan(x*pi/180)|
------+-------------+-------------+-------------+
90.0 | 1.000000000 |-0.000000001*|-1492537313.*|
89.9 | 0.999998477 | 0.001745328 | 572.9574320 |
60.0 | 0.866025404 | 0.500000000 | 1.732050808 |
45.0 | 0.707106781 | 0.707106781 | 1.000000000 |
30.0 | 0.500000000 | 0.866025404 | 0.577350269 |

pi/180 = 1.745329252e-02


HP-15C

x(RAD)| sin(x) | cos(x) | tan(x) |
------+-------------+-------------+-------------+
1.57 | 0.999999683 | 0.000796327 | 1255.765591 |
1.50 | 0.997494987 | 0.070737202 | 14.10141995 |
1.00 | 0.841470985 | 0.540302306 | 1.557407725 |
0.50 | 0.479425539 | 0.877582562 | 0.546302490 |
0.00 | 0.000000000 | 1.000000000 | 0.000000000 |


x(DEG)| sin(x) | cos(x) | tan(x) |
------+-------------+-------------+-------------+
90.0 | 1.000000000 | 0.000000000 | 9.999999 99 |
89.9 | 0.999998477 | 0.001745328 | 572.9572134 |
60.0 | 0.866025404 | 0.500000000 | 1.732050808 |
45.0 | 0.707106781 | 0.707106781 | 1.000000000 |
30.0 | 0.500000000 | 0.866025404 | 0.577350269 |


#7

Thanks for the explanation, Gerson. Did you find the idea somewhere? I assume you did, but not in a book or on the Net but in a corner of your brain. ;)


#8

Marcus,

I certainly knew the Taylor series for sin(x) and cos(x) are similar to those for sinh(x) and cosh(x), except the former ones are alternating series and the latter ones are not. However, it never had occured to me to combine them to approximate the trigonometric functions... not until yesterday morning when playing with my 28S I added the first few terms of the sin(x) and sinh(x) series together and realized this might work. Then I tried cos(x) and cosh(x) and the resulting series appeared to require less steps on the 12C. Anyway, other than rewriting the series, I haven't tried to optimize the program, so I think there is still room for improvement. I think the program runs fast even on the older HP-38, I'll try it on Nonpareil later.

Regards,

Gerson.

#9

I can remember using a sharp 167p ( at least I think it was a 167p)back in the early 1970s, before the HP35 took the world by storm.

It had 100 program steps, basic arithmetic functions, square root and 10 memory registers. Note no trig functions.

It was possible to program accurate trig functions. The only problem was that once the function was generated their was little room left for anything else. All the same we managed to write some basic Surveying programs that at time seemed out of this world. Prior to this you had to use trig tables and curta calculators.

We used infinite series for the trig functions. See below.

Sin x = x - x3/3! + x5/5! - x7/7! + ......

where x is in radians and in the above context x3 means x cubed.

I spent hours programming this machine. It was my introduction to programming. I was totally hooked.

The machine was about the size of a present day lap top and about double the thickness. The program was lost the minute you switched off the calculator. However you could store the program on a punch card. The card had to be manually punched as you wrote the program.
Editing was an interesting exercise. You seemed to go through a stack of cards before you got it right.


#10

Stuart,

I know what you mean. Once I knew a retired municipal surveyor who had a small surveying office at home and spent more time there doing calculations than at the field. He had no computer, only one 11C loaded with of couple of simple programs and one sharp scientific calculator to help him. He showed me a printed spread sheet as an example of the calculations he did. I told him it was nonsense to do that kind of work without a computer and advised him to get at least a pocket computer. He purchased a CASIO PB 700 for about 100 dollars (4 kB RAM, later upgraded to whopping 16 kB!) and I wrote him a BASIC program which did in seconds the work it previously took him a whole day or two.
He had a small museum of old mechanical and electronic calculators he had purchased during his career. He told me he had used trigonometric tables in the beginning. He showed me a Curta Type II, shining in its case, complete with manuals and offered me for about 20 dollars... which I refused to buy because I was not interested in mechanical devices. I remember one of the manuals described a procedure to approximate the sine function on it. Those were the (hard) days!

Cheers,

Gerson.

#11

Nice implementation and explanation!

I hadn't realized that the 12C Platinum carried 12 significant digits (while showing up to 10).

I verified your table is correct using my Platinum that I had to dig out.


#12

Hello Steve,

Thanks for taking the time to key that in and verifying the table. I was curious to know about the Platinum results. As I said, no optimization has been tried yet. The program is fast on the ordinary 12C but somewhat long.

Regards,

Gerson.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP PRIME - Need help for basic program svp. dg1969 4 370 10-08-2013, 04:06 PM
Last Post: dg1969
  Easter Sunday Basic Trigs (HP-12C) Gerson W. Barbosa 29 1,627 04-04-2013, 02:19 PM
Last Post: Gerson W. Barbosa
  "The Basic HP-71" Jeff Davis 3 377 08-30-2012, 12:20 AM
Last Post: Howard Owen
  HP's Tired Basic Calculator Line Jeff 4 324 02-10-2012, 01:33 PM
Last Post: Dirk Mehldau
  After the 15c LE, better chance of a basic RPN calc from HP now? nick lidakis 80 2,891 09-18-2011, 08:15 AM
Last Post: snaggs
  HP 12C, 12C Platinum & 15C iOS App Walter Lam 2 309 06-02-2011, 01:25 PM
Last Post: Andrés C. Rodríguez (Argentina)
  BASIC BEEP Howard Owen 5 293 05-12-2011, 05:03 PM
Last Post: Garth Wilson
  Better Late Than Never--VAL() in HP-71B BASIC Namir 25 1,325 05-08-2011, 11:50 AM
Last Post: Howard Owen
  OT: Sharp PC-1270 BASIC Compiler V3.3 XYZT 1 290 12-18-2010, 05:02 PM
Last Post: Thomas Okken
  Hrast BASIC-4X Discussion HrastProgrammer 6 437 12-06-2010, 01:20 AM
Last Post: HrastProgrammer

Forum Jump: