## Thursday, October 6, 2011

### RPL Programming Tutorial - Part 1 - HP 49g+/50g: Your First Program

RPL Tutorial - Part 1

Introduction

This is a first in a series of RPL programming tutorial with the Hewlett Packard HP 50g Graphics Calculator. RPL stands for the Reverse Polish Lisp programming language. RPL is similar to RPN, since RPL is a combination of RPN (Reverse Polish Notation), Lisp, and Forth.

This series of tutorials cover basic RPL programming. There is a wide variety of mathematical programs, applications, and analysis that can be done with the HP 50g calculator. My goal of this series is to introduce readers to RPL programming so that they get a working knowledge of RPL programming.

The Hewlett Packard graphing series, starting with the HP 28C in the late 1980s, through the HP 48S series, the HP 48G series, the HP 49G at the turn of the century, and the 49g+ all operate on RPL. If you have a 50g or a 49g+, you can follow the programs in this tutorial keystroke by keystroke. Most of the programs shown in this series can be programmed on the 48S, 48G, and the 28 series - but please check your manual: these are older calculators that require different keystrokes.

For example, the programming commands are accessed on the 48S and 48G just by pressing the [PRG] key on the top row. However, on the 49g+ and 50g, you will need to press [LS] [EVAL] to access the program commands.

The author owns a 48SX, 48G, 49g+, and a 50g.

Getting Started

Shift and Soft Keys

For the HP 50g:

[LS] represents the Left Shift key. It is the third key up from the ON button on the left hand side of the keyboard. The key's color is white.

[RS] represents the Right Shfit key. if is the second key up from the ON button on the left hand side of the keyboard. The key's color is orange.

[ALPHA] is the Alpha Key, which allows the user to type alpha and other characters. This is important in naming programs and variables. For the programs in the tutorials, I will use one letter names for variables (i.e. A, B, C, etc..)

Pressing [ALPHA] twice will lock the keyboard into Alpha-Lock mode. This allows you to type more than one letter in succession. Press [ALPHA] again to leave Alpha-Lock mode.

The [ALPHA] key, which is yellow in color, is the fourth key from the ON button on the left hand side of the keyboard.

Finally, the top row of the keyboard consists of six soft keys, labeled F1 to F6. The functions of the soft keys change depending on which menu is currently active.

HP 49g+ Shfit Key Colors:
[ALPHA] - yellow
[LS] - green
[RS] - red

HP 50g Shift Key Colors:
[ALPHA] - yellow
[LS] - white
[RS] - orange

Setting the 50g to RPN Mode

All the programs shown in this tutorial series will be operated in RPN (Reverse Polish Notation) mode. To set the 50g in RPN mode:

1. Press the [MODE] key.
2, Press [F2] (CHOOSE) and select RPN.

Personally I like using soft menus. The HP 49g+ and 50g gives a user a choice to operate using soft menus or scrolling menus. All of the keystrokes in the programs in this tutorial assume that you are using soft keys. To set the calculator for soft keys:

1. Press the [MODE] key
2. Press [F1] (FLAGS) to bring up the calcualtor's flags. Flags are binary operators that dictates the various modes of the calculator. Note: There are user flags that you can set for programming purposes.
3. Scroll up until you see "117" on the left side. If there is a check mark next the 117, the calculator will read "117: Soft MENU". Otherwise, the calculator will read "117: CHOOSE boxes". Press [F3] until 117 is checked. Then press [F6] (OK) twice.

We want the calculator to read "√ 117 Soft MENU". 49g+ users will follow the same instructions.
Programming Basics

Brackets

Programs are enclosed with "pointy" brackets. ( << >> ) All the programming instructions are included with a set of brackets. We can enclose programming instructions in many sets of brackets.

How to Name Programs

You can name a program almost any name you want. Program names are enclosed in single quotes. ( ' ' ) Named programs are shown in the Variables menu. You can simply access the Variables menu by press the [VAR] key. Variables most recently stored are listed first.

Note that:

1. Variable names can be used to name not only programs, but real numbers, complex numbers, constants, graphic databases, matrices, vectors, lists, and even quotes.

2. The Variables menu will only show the first five characters. When a menu is showing (this works with almost any soft menu), you can press [RS] [down arrow] to have the calculator list the full name of each of the commands shown in the current soft menu.
(Edited 4/12/2013: Thank you to Félix Hernández for correcting me on this step - much appreciated!)

3. Variables must start with a letter and can be of any length. No spaces are allowed in variable names.

Acceptable: 'PROG1', 'MYPROG', 'CHANGE%'
Not Acceptable: '123', 'COOL PROGRAM'

How to Name a Program:

1. Press [ ' ].
2. Press [ALPHA] [ALPHA] and type the name. The alphabetic characters are the yellow letters on the keys. Lower case letters can be accessed by first pressing [LS] before the letter. You can access other characters as well by first pressing [RS] before the appropriate key. When done press [ENTER].
3. Press [STO>].

How to delete a Program:

1. Press [ ' ]
2. Press [VAR] and find the program (or variable) you want to delete. Press the appropriate soft key to recall the name.
3. Press [TOOL] then [F5] (PURGE). The program (variable) is deleted.

Finally! Now we get to the good stuff - programming! Programming is one of my favorite features of graphing calculators.

The first program we are going to do is a simple one: find the area of a circle of a given radius. This program takes the radius from Level 1 of the stack and returns a numeric approximation of the area.

Commands Used

&rarr NUM: Convert the contents of Level 1 to an approximate answer.

The Program ACIR

For each program, I will list a series of keystrokes. Following the keystrokes, any notes will be italicized .

[RS] [ + ] (<< >>)
* Start the program
[LS] [ √ ] (x^2)
* Square function - labeled as SQ
[LS] [SPC] (π)
* Inserts π
[ x ]
[RS] [ENTER] (->NUM)
* Convert answer to an approximation
[ENTER]
* Terminate program

[ ' ] [ALPHA] [ALPHA]
[F1] (A) [F3] (C) [TOOL] (I) [ √ ] (R) [ENTER] [STO>]

Store the program in variable ACIR

The Program:

<< SQ π * ->NUM >>

Running ACIR

2. Press [VAR] - find ACIR and press the appropriate soft key. Press [NXT] if necessary.

An alternative way:

2. Press [ ' ] [ALPHA] [ALPHA] type ACIR and press [ENTER].
3. Press [EVAL] to run the program.

Results:

Radius = 6; Result = 113.09734
Radius = 4.08; Result = 52.29621

Hint: You can look at program (to edit, view, etc), by pressing [ ' ], typing the name, and pressing [LS] [STO>] (RCL) .

Be sure to check this blog for future tutorials on RPL Programming. Up next, local variables. See you next time! - Eddie

This tutorial is property of Edward Shore. Mass reproduction or distribution requires express permission by the author.

1. Thanks Eddie! This is nice step #1 for me for passing the learning curve of my HP50g :)

2. Thanks for the compliment Vitasam.

1. I never have had such a powerful thing as HP50g, only old Soviet programmable RPN calculator Elektronika MK-52 and 61 (http://en.wikipedia.org/wiki/Elektronika_MK-61)

But maybe it will be interesting for you: there is a modern version of those calcs available. Made by private Russian company in a very limited edition, with very industrial design (or maybe without design at all). Looks ugly, but features are very interesting: LPT port, RS232 port, SPI port, 4-channels ADC input. I have one and here, for example, SPI-port demo: http://youtu.be/wFCyhGbNCfM

3. Does anybody know the keystroke to create a compiled local variable? Particularly, how do I introduce the left arrow in my program?

4. Thanks Eddie. I'm going to the "U of E" and work through all of your lessons instead of whining about my ignorance of RPL. Thanks for the great resources! !!

5. @andre: left arrow is found on the 49g+ by keying right shift and chars. There's a whole bank of characters. I select by hitting echo and enter. I'm trying to work with compiled vars to tidy up my programs. Any hints?

6. Some characters have a keyboard shortcut (example, ALPHA, hold right shift, 6 gives the degrees character; ALPHA, right shift, 2 gives the exclamation point). In the CHARS screen, if that character has a keyboard shortcut, it will be indicated on the bottom right hand of the screen. Unfortunately, I don't think there is a keyboard shortcut for the left arrow.

Eddie

7. In "How to name programs" section 2, you said " you can press [LS] [down arrow] to have the calculator list the full name"

This did not work on my 50g. I had to use the Orange [RS] key and [down arrow] keys

1. Félix,

Thank you. I have made the correction in the blog. Very much appreciated.

Eddie

8. We Hold our Tutors to a Higher Standard, and Pay our Tutors More Fairly, than nearly any other Tutoring Company.Thus, we have Better (and more Experienced) Tutors.We accept only the top tutor applicants, and will never compromise our selectivity in order to artificially inflate our ranks. In addition, every member of the Team is required to have recently scored in the 95th percentile or above on any standardized test that he/she teaches.Math Tutor Austin, Math Tutor Atlanta, Math Tutor Houston, Math Tutor Seattle.
Science Tutor Las Vegas | Math Tutor Hawaii | Math Tutor Las Vegas | Tutor for kids Las Vegas | Math Tutor Charlotte | Math Tutor Phoenix | Math Tutor Los Angeles | Math Tutor Boston | Math Tutor New York | Math Tutor Denver | Math Tutor Chicago |

9. hallo teman2x jika mau belajar komputer online di asianbrilliant aja , enak loh bisa belajar dimana saja kapan saja lebih
flexible. kalo mau bukti bisa di lihat websitenya di www.asianbrilliant.com atau cari di google kursus
komputer
, kursus online, kursus, tempat kursus

10. anda sedang mencari tempat kursus private? kunjungi aja web ini www.smartsukses.com atau smart sukses , les privat , guru datang ke rumah

11. Can someone help me, please?
I inserted a 2GB micro SD card into my HP50g. It is listed when I look at FILES, but I receive an error report whenever I try to format it or interact with it. Is it possible that 2GB is too big? I can't find anything in the User Guide or Specs.
Bruce

1. Bruce,

I think the HP 50g only works with SD cards, not micro SD cards. I am currently using an SD card of 2 GB. The card needs to be formatted in FAT 16 or FAT 32.

Hope that helps,

Eddie

2. Thanks Eddie for your speedy response, but I just tried an ordinary SD 2GB card, and when I attempt to format it, it returns an error message "Error: Disk Format Error".
I removed it from the HP50g and inserted it into my HP Notebook and did a quick FAT format, but when I re-insert it into the calculator and try to format, I receive the same error message.

12. It was so nice article.I was really satisified by seeing this article and we are also giving QA online training.The QA online training is one of the best QA online training institute in worldwide.

13. Q!a,

Thank you for the compliment. Much appreciated.

Eddie

14. Im making my first program on an HP48 emulator. The program is << 2 * --> NUM >> but I put the arrow to the right of the >> and press ENTER and it highlights the >> and says Invalid Syntax. What am I doing wrong? How do I get this simple program to display the result?

1. The arrow needs to be before "NUM". The double arrow ">>" indicator ends a program or a subroutine.

15. Programming is very interesting and creative thing if you do it with love. Your blog code helps a lot to beginners to learn programming from basic to advance level. I really love this blog because I learn a lot from here and this process is still continuing.
Love from Pro Programmer

16. Is there any code to set the Alpha keyboard on ?

if a program requests to input a name an then numbers (es: using INFORM ) I must press "ALPHA", insert the name and the press again ALPHA to insert numbers: if I well remember, on the old HP (41c....) it was possible to activate and de-activate the alphanumeric keyboard from inside a programm using flags or a line of code. Is there something on the HP50G to do this using RPN code

### Fun with the FX-603P Emulator

Fun with the FX-603P Emulator Author for the Emulator:   Martin Krischik Link to Emulator (Android):   https://play.goo...