Tuesday, October 11, 2011

RPL Programming Tutorial - Part 9 - HP 49g+/50g: Temporary Menus and a Simple Statistics Application

Make Your Own Menus

Today in Part 9, we will create two programs where menus are created. The first one is a simple program involving free fall. The second program is a more complex menu that allows users to easily enter statistics and perform simple analysis.

Creating menus in RPL is not hard - but you really have to keep track of what you are doing because it can be easy to be lost in the symbols that are involved. These two programs may the ones to insert line breaks (done by [RS] [ . ]) to make program entry easier to see.

The menu structure in RPL is:

{ { "title" { << program >> << left shift program >> << right shift program >> } repeat the last nested list as needed }

A simplified structure is:

{ { "title" << program >>} repeat the last nested list as needed }

In Part 9, we will use the simplified structure in both the programs.

Either of the structures are followed by either MENU or TMENU.

MENU: Creates a user-defined menu and also replaces the calculator's custom menu for future use. To access the custom menu, press [LS] [MODE] (CUSTOM).

TMENU: Works the same as MENU except the user menu does not replace the calculator's custom menu for future use.

The Program FALL

This program calculates the length of a free fall of an object dropped straight down in either feet or meters. The gravitational constant is determined by the desired measurement. Air resistance is ignored in this calculation.

Comments are italicized and start with an asterisk. This program assumes the time (in seconds) is on Level 1.

g = 9.80665 m/s^2 = 32.1740468 ft/s^2

d = -1/2 * t^2 * g

[RS] [ + ] (<< >>) [LS] [ + ] ( { } ) [RS] [ . ]**
* The [RS] [ . ] sequence is the carriage return sequence and is not required. I just put the sequence in here to program entry look better.
[LS] [ + ] ( { } ) [RS] [ . ] [RS] [ x ] ( " " ) [ALPHA] [ALPHA] [F6] (F) [COS] (T) [ALPHA] [ &rarr ] [RS] [ + ] (<< >>)
* Creates the first menu key "FT"
[LS] [ √ ] (x^2) 2 [ ÷ ] 32.1740468 [ x ] [RS] [ENTER] ( &rarr NUM)
* The commands associated with "FT"
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* Exits the first nested list, you want to be in between the two right list brackets. ( } )
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] ( " " ) [ALPHA] [HIST] (M) [ &rarr ]
* Creates the second menu key "M"
[RS] [ + ] (<< >>) [LS] [ √ ] (x^2) 2 [ ÷ ] 9.80665 [ x ] [RS] [ENTER] (&rarr NUM)
* The commands associated with "M"
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* Exits the second nested list and the menu structure.
[LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [F3] (TMENU)
* Enters the TMENU command - you can use the MENU command (F1) desired.
[ENTER]
* Terminates program entry

[ ' ] [ALPHA] [ALPHA] [F6] (F) [F1] (A) [NXT] (L) [NXT] (L) [ENTER] [STO>]

The completed program:

<< {
{"FT" << SQ 2 / 32.1740468 * &rarr NUM >>}
{"M" << SQ 2 / 9.80665 * &rarr NUM >>} } TMENU >>


Doesn't look that complicated does it?

Instructions:

1. Enter the time in seconds.
2. Run FALL
3. Select either [F1] for distance in feet, or [F2] for distance in meters.

Example:

I am going to drop an egg from a building. The fall lasts 3 seconds. How far did it go?

In Feet:

Run FALL, 3 [F1] (FT)

Result: 144.7832106 feet

In Meters:

Run FALL, 3 [F2] (M)

Result: 44.129925 meters

The Statistics Program

This program will allow the user to easily enter data and calculate the mean, standard deviation, and the sum of the data. The program creates a six key menu where:

* [F1] (CLEAR) clears the statistics data matrix and the stack
* [F2] (∑+) enters the next data point and clears the stack. It also returns the number of data points in the statistics data matrix.
* [F3] (∑-) deletes the latest data point and clears the stack. It also returns the number of data points in the statistics data matrix.
* [F4] (MEAN) calculates the mean of each column of the statistics data matrix.
* [F5] (SDEV) calculates the standard deviation of each column of the statistics data matrix.
* [F6] (SUM) calculates the sum of each column of the statistics data matrix.

The statistics data matrix is the system variable ∑DAT.

The Program STAT1

Note:

The key sequence [RS] [ . ] inserts a carriage return to improve readability of program entry and is not required.

[RS] [ + ] (<< >>) [LS] [ + ] ( { } ) [RS] [ . ]
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [F3] (C) [NXT] (L) [SIN] (S) [COS] (T) [ALPHA] [ &rarr ]
[RS] [ + ] (<< >>) [RS] [SYMB] (CAT) [ALPHA] [F3] (C) find CL∑ [F6] (OK) [RS] [backspace] (CLEAR)
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [F1] (A) [NXT] (L) [NXT] (L) [SPC] [F3] (C) [NXT] (L) [F5] (E) [F1] (A) [ √ ] (R)

* The first menu item "CLST" and its instructions
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* To get in between the two right list brackets } }
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] ( " " ) [RS] [SIN] (∑) [ &larr ] [ &larr ] [backspace] [ &rarr ] [ALPHA] [ + ]
* To type "∑+ "
[ &rarr ] [ &rarr ] [RS] [ + ] (<< >>) [RS] [SYMB] (CAT) [RS] [SIN] (∑) find ∑+ [F6] (OK)
[RS] [backspace] (CLEAR)
[RS] [SYMB] (CAT) [ALPHA] [EVAL] (N) find N∑ [F6] (OK)

* The second menu item "∑+" and its instructions
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* To get in between the two right list brackets } }
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] ( " " ) [RS] [SIN] (∑) [ &larr ] [ &larr ] [backspace] [ &rarr ] [ALPHA] [ - ] [ &rarr ] [ &rarr ]
[RS] [ + ] ( << >>) [RS] [SYMB] (CAT) [RS] [SIN] (∑) find ∑- [F6] (OK) [RS] [backspace] (CLEAR)
[RS] [SYMB] (CAT) [ALPHA] [EVAL] (N) find N∑ [F6] (OK)

* The third menu item "∑-" and its instructions
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* To get in between the two right list brackets } }
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] [ALPHA] [ALPHA] [HIST] (M) [F5] (E) [F1] (A) [EVAL] (N) [ALPHA]
[ &rarr ] [RS] [ + ] (<< >>) [RS] [SYMB] (CAT) [ALPHA] [HIST] (M) find MEAN [F6] (OK)

* The fourth menu item "MEAN" and its instructions
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* To get in between the two right list brackets } } - just two menu commands to go!
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [SIN] (S) [F4] (D) [F5] (E) [EEX] (V) [ALPHA]
[ &rarr ] [RS] [ + ] (<< >>) [RS] [SYMB] (CAT) [ALPHA] [SIN] (S) find SDEV [F6] (OK)

* The fifth menu item "SDEV" and its instructions
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* To get in the between the two right list brackets } } - last time for this program
[LS] [ + ] ( { } ) [RS] [ . ]
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [SIN] (S) [TAN] (U) [HIST] (M) [ALPHA]
[ &rarr ] [RS] [ + ] (<< >>) [RS] [SYMB] (CAT) [ALPHA] [COS] (T) find TOT [F6] (OK)

* The sixth (and final) menu item "SUM" and its instructions
[ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ] [ &rarr ]
* To get past the two right list brackets } }
[LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [F3] (TMENU) [ENTER]
* Enter the TMENU command and terminate program entry

[ ' ] [ALPHA] [ALPHA] [SIN] (S) [COS] (T) [F1] (A) [COS] (T) 1 [ENTER] [STO>]

The completed program:

<< {
{ "CLST" << CL∑ CLEAR "ALL CLEAR" >> }
{ "∑+" << ∑+ CLEAR N∑ >> }
{ "∑-" << ∑- CLEAR N∑ >> }
{ "MEAN" << MEAN >> }
{ "SDEV" << SDEV >> }
{ "TOT" << TOT >> } } TMENU >>


Instructions:

1. Run STAT1
2. Use the following soft keys for the following functions:

* [F1] (CLEAR) clears the statistics data matrix and the stack
* [F2] (∑+) enters the next data point and clears the stack. It also returns the number of data points in the statistics data matrix. For entering multi-variate data, see the hint below.
* [F3] (∑-) deletes the latest data point and clears the stack. It also returns the number of data points in the statistics data matrix.
* [F4] (MEAN) calculates the mean of each column of the statistics data matrix.
* [F5] (SDEV) calculates the standard deviation of each column of the statistics data matrix.
* [F6] (SUM) calculates the sum of each column of the statistics data matrix.

Hint:

In STAT1, you can enter multivariate data. To do so, first clear the statistics matrix. Then for each point, press [LS] [ x ] ( [ ] ). Separate each point with a comma or space. The press [F2] (∑+). You can operate the other commands (∑-, MEAN, SDEV, SUM) like normal.

Example:

A research company compiled retrieved a list of the last 15 winning amounts from a popular, long-running game show. The company wants to find the average winning amount, it's deviation, and the total amount won.

Data:
$ 35,000
$ 27,000
$ 15,000
$ 16,000
$ 9,000
$ 7,500
$ 34,600
$ 18,800
$ 24,300
$ 40,000
$ 11,500
$ 3,800
$ 17,600
$ 25,000
$ 35,000

Keystrokes:

Remember you can remove the last data point entered by pressing [F3] (∑-).

Run STAT1.
[F1] (CLST) - display says "ALL CLEAR"
35000 [F2] (∑+) - displays says 1
27000 [F2] (∑+) - displays says 2
15000 [F2] (∑+) - displays says 3
16000 [F2] (∑+) - displays says 4
9000 [F2] (∑+) - displays says 5
7500 [F2] (∑+) - displays says 6 (6 data entry points so far)
34600 [F2] (∑+) - displays says 7
18800 [F2] (∑+) - displays says 8
24300 [F2] (∑+) - displays says 9
40000 [F2] (∑+) - displays says 10
11500 [F2] (∑+) - displays says 11
3800 [F2] (∑+) - displays says 12
17600 [F2] (∑+) - displays says 13
25000 [F2] (∑+) - displays says 14
35000 [F2] (∑+) - displays says 15
[F4] (MEAN) - $21,340 is the average amount won.
[F5] (SDEV) - $11,303.7793933 is the standard deviation
[F6] (SUM) - $321,000 is the total winnings

This ends Part 9 of the RPL Programming Tutorial. Until next time, Eddie.


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