HP Forums
Basic trig functions for the HP-12C - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Basic trig functions for the HP-12C (/thread-68672.html)



Basic trig functions for the HP-12C - GWB - 02-05-2005

Basic Trig Functions for the HP-12C

01 57.29577951 ; 180/pi: degree to radian conversion factor
12 /
13 STO 0
14 STO 1
15 1
16 STO 3 ; n:=1
17 9 ; steps 17 to 23 provide automatic accuracy
18 1/x ; according to the current number of decimal
19 ENTER ; places in the display
20 RND ;
21 - ;
22 12x ; intended to multiply by 10, used the built-in
23 STO 4 ; 12x instead in order to save two steps.
24 RCL 3
25 2 * 1 +
29 ENTER ENTER
31 RCL 0
32 x<>y
33 y^x
34 x<>y
35 n!
36 /
37 ENTER
38 1 CHS
40 RCL 3
41 y^x *
43 STO + 1
44 1
45 STO + 3 ; n:=n+1
46 ROLLDN ;
47 ENTER * SQRT ; these are equivalent to ABS
50 RCL 4
51 x=<y
52 GTO 24
53 1
54 RCL 1 ; sin(x)
55 ENTER
56 * - SQRT ; cos(x)
59 STO 2
60 RCL 1

Usage:

Enter angle in degrees, 0 =< x <= 180 (prefer however the
range of 0 to +/-90 degrees for greater speed and accuracy). This
range is for sine only. The range for cosine is 0 to 90 degrees.

R/S => sin(x)

x<>y => cos(x)

/ => tan(x)

Registers:

R0: angle converted to radians
R1: sin(x)
R2: cos(x)
R3: number of iterations minus 1
R4: accuracy

Running time will depend upon the number of selected decimal places:

Ex.: sin(30.0)=0.5 (0.4996741794, 1 iteration, 5.5 s)
sin(30.000)=0.500 (0.5000021326, 2 iterations, 8.5 s)
sin(30.0000)=0.5000 (0.4999999919, 3 iterations, 11.5 s)
sin(30.00000000)=0.50000000 (0.5000000001, 4 iterations, 14.5 s)

Reference:

sin(x) = x + SUM{n=1, inf, [(-1)^n . x^(2n+1)]/(2n+1)!}; 0 =< x =< pi

cos(x) = SQRT[1 - sin^2(x)];

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

http://www.rskey.org/gene/calcgene/38trig.htm (got the sine expansion there, which I had already forgotten).

Regards,

GWB


Edited: 6 Feb 2005, 10:06 p.m. after one or more responses were posted


Re: Basic trig functions for the HP-12C - Vieira, Luiz C. (Brazil) - 02-05-2005

Olá, Gerson; (Hello)

There is an excellent part of this site named Articles Forum where contributors add important information. One of these is from Viktor Toth and explore the same theme. I'm sure you will appreciate having a look at it here. Also, Valentin Albillo proposed another great solution, but I failled finding the link for it. It's an e-paper (a PDF) available at HPCC.

Your version is closer to Valentin's because both use [n!] and [y^x]. Viktor Toth uses a sequence of multiplications in the loop, so it also computes both n! and y^x without using the 'native' HP12C functions themselves. The idea was so interesting for me that I actually used Viktor's scheme to produce this one my own for the HP16C. I'm still in debt with the inverses...

It's always good to see new versions of classical problems. I once wrote a program to compute sin(x) for the HP38C, but I lost it. What I cannot forget is the big smille in the beautifull face of the HP38C's owner...

Good to see your listings here, 'cumpádi' (fella).

Cheers.

Luiz (Brazil)

Edited: 5 Feb 2005, 7:51 p.m.


Re: Basic trig functions for the HP-12C - GWB - 02-05-2005

Olá Luiz,

Thanks for your remarks. Machine limitations is always an invite to creativeness. I have not submit anything to the Articles Forum just because I don't have anything realling important. I'll take a closer look to your program, it should run faster, since it avoids both y^x and n!. Well, I bought the 12C this morning, while they are still avaible, and wrote this program in the afternoon (too much to learn to creating something really innovative).
By the way, I googled for you book and found it available only in two stores, one happens to be just for blocks away from where I live (I haven't bought it, a brand new book, because I want to pay R$ 15,00 and the bookseller wants R$ 17,00 for it - sometimes my Minas blood I inherited from my father shows :), sometimes not - I paid about USD 160.00 for my brand new 12C at WalMart).

See you,

Gerson.


Re: Basic trig functions for the HP-12C - Vieira, Luiz C. (Brazil) - 02-06-2005

Hi, Gerson;

Hey, thanks for telling me that my book is still available... I was not sure it was.

About the HP12C: is it a Platinum or a plain HP12C? You see, I have both, and I like the additional features available with the HP12Cp. I don't use the algebraic mode unless it is strictly necessary (students with doubts, for exemple), but the extra memory allows for new, bold 'adventures'.

I agree with you when you say: 'Machine limitations is always an invite to creativeness.' The 'taste of victory' when reducing the number of steps or the quantity of bytes in a program is unique. Sometimes we, the 'creators', are the only ones to understand the meaning of this, but what to do? Today we have so much memory available with computers and portable devices that just a few 'entrepreneurs' go ahead with the job...

About the articles forum: I guess your version of the trig functions for the HP12C deserves a place in there (I see I did not even suggested this fact in my last post... Sorry!). It is original, so it has different approaches.

Best regards.

Luiz


Re: Basic trig functions for the HP-12C - Vassilis Prevelakis - 02-06-2005

GWB wrote:
> accuracy is not granted for negative angles due to
> lack of ABS function


You can simulate ABS with

ENTER^
*
SQRTx

**vp




Re: Basic trig functions for the HP-12C - GWB - 02-06-2005

Thanks Vassilis,

I had just figured it out when I was rewriting the program about half an hour ago. I read your mind :)

I included automatic accuracy based on the number of decimal places in the display. Also deleted an extra ENTER and ROLLDN. Please see the version.

Any remark is welcome,

Gerson W. Barbosa


Here is the link to the PDF :-) - Valentin Albillo - 02-07-2005

Hi Luiz, Gerson:

Luiz posted:


Also, Valentin Albillo proposed
another great solution, but I failled finding the link for it. It's an e-paper (a PDF) available at HPCC.

Thanks for your kind words, here is the link to the PDF version of my 10-page article " HP-12C Tried & Tricky Trigonometrics", which was published in Datafile V21N1, January-February 2002:

HP-12C Tried & Tricky Trigonometrics

Apart from a discussion of the program itself, it includes performance tables (timing/accuracy) plus some very interesting examples. You'll find it extremely tricky to beat my times and the numerical precision of my results ! :-)

Best regards from V.


(deleted post) - deleted - 02-07-2005

This Message was deleted. This empty message preserves the threading when a post with followup(s) is deleted.


Re: Here is the link to the PDF :-) - Vieira, Luiz C. (Brazil) - 02-07-2005

Hi, Gerson;

just wondering about the HP38C program...

The HP12C programming features are exactly the same found in the HP38E/C (I own one of each). They both have GTO nn, being nn the number of the step you want it to jump to. Except for bonds, depreciation and computing [n] (the HP12C gives only integer values when computing [n], while the HP38E/C may return non-integer values), all of the rest is the same. Also, the HP38E/C have a switch for selecting both BEG/END and D.MY/M.DY modes simultaneously and they have no [ON]&[key] self tests, only [STO][ENTER].

I tried to find the TRIG program for the HP38C and did not succeed. Do you still have the link OR the listing itself? I'd like to take a look at it. Reference purposes...

Best regards.

Luiz


38c trig program - Gene - 02-07-2005

...came from an old PPC Journal.

Can be found at www.rskey.org/gene

Just scroll down a bit on the page.

Gene


Re: Here is the link to the PDF :-) - Valentin Albillo - 02-07-2005

Hi, Gerson:

Gerson posted:

"Thanks for the link. I had been looking for it, but all I could find was (good) references to it."

You're welcome. Should you want any of my past Datafile articles in PDF format, just ask. Besides the trigonometrics one I've explored several other interesting aspects of HP-12C programming in these two articles as well:


"I'd rather have a 15C because of the way it handles complex numbers and performs matrix operations. Too bad they are not available any more."

Oh, but they are. At eBay ... Besides complex numbers and matrix operations (which includes solving systems of linear equations), it also does numerical integration and root finding, gamma, hyperbolics, linear regression, permutations, combinations, random number generation, etc, etc. A passable machine, methinks ! ;-)

"I think HP could have included some basic scientific functions in their new 12C Platinum."

Other brands did much better. SHARP, for instance, had a number of "Business/Financial Pocket Computers", like this SHARP PC-1421 model, a slim, all-metallic, dot-matrix alphanumeric display, large RAM, fast machine which featured a full set of financial functions (including NPV, IRR, etc) plus a full-featured BASIC-language programming environment which of course included 2-dimensional dinamic arrays, strings, and all the usual mathematical functions, trigonometrics included. Needless to say, you could use the financial functions as keywords in your BASIC programs, which meant incredible computing power for financial applications.

By the way, contrary to what most people believe, trigonometric functions are indeed used in advanced financial applications, just have a look at this paper published in the Journal of Financial Economics:

Spanning and Derivative-Security Valuation

These kind of applications can be programmed in a SHARP PC-1421, not so in any of HP's financial models.

Best regards from V.


Link has additional (weird) characters...(was: 38c trig program) - Vieira, Luiz C. (Brazil) - 02-07-2005

Hi, Gene;

thanks for the additional info.

I tried to jump through the link you post but it failed. If you use it directly you'll have:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/www.rskey.org/gene

and it generates an error. I used "copy and paste" and changed it to what you wrote:

http://www.rskey.org/gene

and it worked fine. It jumped to your own page, right?

Thanks. I'll reach the artiocle, now.

Best regards.

Luiz.


I saw the trig program... - Vieira, Luiz C. (Brazil) - 02-07-2005

Hi Gene, Gerson, folks;

the trig program mentioned there (earlier at HPCC) uses a fixed number of therms (four) in the sin(x) and cos(x) series. It has no loop for error control/reduction.

Made me "remember the days of the old school yard" (Cat Stevens, right?), at the university, when we had to compute sin(x), cos(x) and the like, and the intermediate therms might be written down on paper (three, sometimes four) so the teacher could "see" what we had done.

Wow! Some 'nostalgic' moments...

Cheers and thanks again, Gene! It's always good to see how things actualy work.

Best regards.

Luiz (Brazil)


(deleted post) - deleted - 02-07-2005

This Message was deleted. This empty message preserves the threading when a post with followup(s) is deleted.


(deleted post) - deleted - 02-07-2005

This Message was deleted. This empty message preserves the threading when a post with followup(s) is deleted.


Re: I saw the trig program... - Vieira, Luiz C. (Brazil) - 02-07-2005

Hey, Gerson;

you bet... at least about me. I'm having fun at home, dealing with my stuff. Each one has his own way to get inner satisfaction with outer activities. I like usefull activities in general. Of course, I'm talking about doing things by my own...

I include posting and reading messages here as pleasant and rewarding. We always read or write something usefull.

Even this off-topic words of mine...

Best regards and thanks. I did not notice the link you added to your post... Sorry!

Cheers.

Luiz.


Re: Here is the link to the PDF :-) - Valentin Albillo - 02-08-2005

Hi, Gerson:

Gerson posted:

"I've taken a look at your papers. Really impressive work! Are you a mathematicien? (You are acquainted with heavy subjects like quintics)."

Just an amateur. Quintics have always been a pet topic of mine since I was 15 or so, I'm fairly acquainted with them by now. As for heavy subjects, just have a look at fractional calculus for a change. Or if you want to do a little I+D, try your hand at writing a program to compute the permanent of an NxN square matrix in polynomial (not exponential) time, you'll get instant recognition.

"I had one 15C in 1984 but I sold it to my youngest brother two years later. I also gave to another brother an
11C, for his Agriculture studies. Both have their calculators flawlessly working till today."


Perhaps a little arm-twisting would be in order to get them back. Make them an offer they can't refuse ... but don't forget to make it look like an accident :-)

"It is quite a challenge. I wonder if I ever will take it."

You're welcome to try, under the same specifications of functionality, range, and accuracy, of course.

Thanks for your posts and best regards from V.


Re: Here is the link to the PDF :-) - Vieira, Luiz C. (Brazil) - 02-08-2005

Quote:
Perhaps a little arm-twisting would be in order to get them back. Make them an offer they can't refuse ... but don't forget to make it look like an accident :-)
Bad Valentin, bad Valentin... Made me remember Adams' books. BTW, I'm reading them and comparing the original text to the translated one. I got into two conclusions:

1- the translator is a hell-of-a writer; he wrote a damn good piece of good stuff. He uses Portuguese terms common in Brazilian speech that make the translated text completely hilarious;

2 - getting to this conclusion, I'm now taking double seriously your suggestion "to polish my English skills" so I'll take the original text in another perspective.

You see, I laugh a lot when reading the original Hitchhiker's Guide, but in some descriptive passages, the translator used non-conventional terms that made the translation hilarious as well. Now I have two good readings!

Best regards.

Luiz (Brazil)


(deleted post) - deleted - 02-08-2005

This Message was deleted. This empty message preserves the threading when a post with followup(s) is deleted.


Re: HP-15C !? (twas: It'll be back!) - Valentin Albillo - 02-09-2005

Hi again, Gerson:

Gerson posted:

"By what he told me he used mostly +, -, *, /, %, D%, 1/x, no SIN, COS, etc, so I think he'll do well with the 12C."

Good. I'm glad if my "arm-twisting" suggestion played a part, however small, in your getting the HP-15C back where it belongs.

"By the way, I enjoyed your time travel adventure with Sir Isaac Newton. Just think you shoud have taken the 15C along."

No, that would've been a terrible mistake, as the one fundamental precaution you must adhere to whenever time travel is involved, as in Time Voyager, is that you must avoid changing history at all costs. The HP-15C boasts root finding using (precisely!) Newton's own method, which he hadn't "invented" at the time of the rendezvous ! He was to use the machine to help him discover it, not reverse-engineer it ! :-)

Also, the HP-15C includes matrix operations, and matrix algebra was unknown to Newton, since he died in 1727 and it wasn't until 1850 when Silvester and Cailey formulated the concept of matrices, so exposing him to their concept and uses well ahead of their proper time would probably result in major disturbances to the timeline, and that would be a big no-no.

An HP48/49 is also out of the question.

Thanks for your interest and best regards from V.