Monday, October 24, 2011

RPL Programming Tutorial - Part 17 - HP 49g+/50g: System Flags

Flags

Welcome to Part 17 of the RPL Tutorial for the Hewlett Packard 49g+ and 50g calculators. Today we will work with flags.

There are two types of flags: system and user flags.

User flags do not have any pre-defined meaning except for what the programmer gives them. User flags are flags 1 through 127.

System flags are the flags that set the various modes of the calculator, and they are -1 to -127. Depending on how these flags are clear (turned off) or set (turned on) dictate how the calculator operates.

The Flag Menu

Keystroke sequence: [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F3] (FLAG)

[F1] (SF) - Set Flag. Turns the flag on. The flag number is on level 1 of the stack.
[F2] (CF) - Clear Flag. Turns the flag off. The flag number is on level 1 of the stack.
[F3] (FS?) - Set Flag Test. Tests if a flag is set. Returns 1 if the flag is set, 0 if it isn't.
[F4] (FC?) - Clear Flag Test. Tests if a flag is cleared. Returns 1 if the flag is cleared, 0 if it isn't.
[F5] (FS?C) - Tests if a flag is set - then clears the flag regardless of the result.
[F6] (FC?C) - Tests if a flag is clear - then clears the flag regardless of the result.

Some Common System Flags

Flag -13
Set: Built-in Time Value of Money calculations - assumes all payments are paid at the beginning of each period. (BGN mode on financial calculators)
Clear: Built-in Time Value of Money calculations - assumes all payments are paid at the end of each period. (END mode on financial calculators)

Flag -27
Set: Displays complex numbers as 'x + y*i'
Clear: Displays complex numbers as (x,y)

Flag -28
Set: Multiple equations are plotted simultaneously
Clear: Multiple equations are plotted sequentially

Flag -40
Set: The clock is displayed
Clear: The clock is not displayed

Flag -41
Set: 24 Hour Clock
Clear: 12 Hour Clock

Flag -42
Set: Day/Month/Year date format
Clear: Month/Day/Year date format

Flag -51
Set: The fraction mark is a comma ( , )
Clear: The fraction mark is a decimal point ( . )

Flag -60
Set: Pressing [ALPHA] once sets alpha-lock
Clear: Pressing [ALPHA] twice sets alpha-lock (default)

Flag -65
Set: Only level 1 on the stack displays multiple lines
Clear: All the levels on the stack displays multiple lines

Flag -79
Set: Single-line expressions
Clear: Textbook expressions

Flag -95
Set: Algebraic Mode (factory default)
Clear: RPN Mode

Flag -103
Set: Complex Number Mode (C indicator)
Clear: Real Number Mode (R indicator)

Keyboard Toggle: Hold [LS] while pressing [TOOL] (i)

Flag -105
Set: Approximate Mode (~ indicator)
Clear: Exact Mode (= indicator)

Keyboard Toggle: Hold [RS] while pressing [ENTER] (→NUM)

Flag -114
Set: Polynomials are shown in increase power order
(a0 + a1 * x + a2 * x^2 + ... + an * x^n)
Clear: Polynomials are shown in decrease power order
(an * x^n + ... + a2 * x^2 + a1 * x + a0)

Angle setting using flags:
Degree: Clear flags -17 and -18
Radians: Set flag -17, clear flag -18
Gradians: Set flag -18, clear flag -17

By commands:
Hold [LS] while pressing [MODE], [F2] (ANGLE)
F1: DEG, F2: RAD, F3: GRAD

PUSH and POP

A very handy pair of programming commands is PUSH and POP. Both commands are found in the catalog. These commands allow the user to save the calculator's mode settings with PUSH, change them during program execution, and recall them with POP.

PUSH: saves the current status of the flags

POP: restores the last saved status of the flags

The Program ROOTZ

This program will allow the user to calculate the xth root of any number. The user can request through a temporary soft menu:

[F1] (PRN): The principal root. This is the root that most, if not all, calculators return if the xth root (x√y) command is used. For square roots, this is the positive square root.

[F2] (REAL): All real roots to be returned. Real mode is set during execution.

[F3] (ALL): All roots, real and complex, to be returned. Complex mode is set during execution.

ROOTZ also purges the variable X and sets the calculator to Approximate mode.

Caution: ROOTZ works with real radicands (y). Complex radicands will return errors or undesired results.

Keystrokes:
[RS] [ + ] ( << >> )
105 [+/-] [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F3] (FLAG) [F1] (SF)

* Set the calculator to approximate mode
[LS] [ + ] ( { } )
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [SYMB] (P) [ √ ] (R) [EVAL] (N) [ALPHA] [ → ]
[RS] [ + ] ( << >> ) [RS] [ √ ] (x√y) [RS] [ENTER] (→NUM)

* Enters the commands for the PRN option (F1)
[ → ] [ → ] [ → ] [ → ]
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [ √ ] (R) [F5] (E) [F1] (A) [NXT] (L) [ALPHA] [ → ]
[RS] [ + ] ( << >> ) 103 [+/-] hold [LS] press [MODE] [F3] (FLAG) [F2] (CF)
[ ' ] [big X] [ → ] [LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE)
[big X] [LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[y^x] [L2] (SWAP) [ - ] [big X] [SYMB] [F5] (SOLVE) [F6] (ZEROS)

* Enters the commands for the REAL option (F2)
[ → ] [ → ] [ → ] [ → ]
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [F1] (A) [NXT] (L) [NXT] (L) [ALPHA] [ → ]
[RS] [ + ] ( << >> ) 103 [+/-] hold [LS] press [MODE] [F3] (FLAG) [F1] (SF)
[ ' ] [big X] [ → ] [LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE)
[big X] [LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[y^x] [L2] (SWAP) [ - ] [big X] [SYMB] [F5] (SOLVE) [F6] (ZEROS)

* Enter the commands for the ALL option (F3)
[ → ] [ → ] [ → ] [ → ] [ → ]
hold [LS] press [MODE] [F5] (MENU) [F3] (TMENU)

* Enters the TMENU command
[ENTER]
* Terminate program entry.


[ ' ] [ALPHA] [ALPHA] [ √ ] (R) [ ' ] (O) [ ' ] (O) [COS] (T) [ ÷ ] (Z) [ENTER] [STO>]

The completed program:

<< -105 SF
{ { "PRN" << XROOT →NUM >> }
{ "REAL" << -103 CF 'X' PURGE X SWAP ^ SWAP - X ZEROS >> }
{ "ALL" << -103 SF 'X' PURGE X SWAP ^ SWAP - X ZEROS >> } }
TMENU >>


Instructions:

1. Enter y (the radicand - goes underneath the radical √ )
2. Enter x

Complex numbers are displayed as coordinate pairs (real part,imaginary part).

Example:

1. The 4th roots of 8:

Principal: 1.618179283051

Real Roots: {1.618179283051, -1.618179283051}

All Roots: {1.618179283051, -1.618179283051, (0, -1.618179283051),
(0, 1.618179283051)}

2. The 3rd roots of -7:

Principal: -1.91293118277

Real Roots: -1.91293118277

All Roots: {(.956465591386, -1.65664699997), (.956465591386, 1.65664699997),
(-1.91293118277, 0)}

This concludes Part 17 of our RPL tutorial. Until next time, happy programming, Eddie.



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

RPL Programming Tutorial - Part 16 - HP 49g+/50g: Choose Box

Giving Yourself Choices

Welcome to Part 16 of the RPL programming tutorial. Today we will work with CHOOSE boxes.

Note: The CHOOSE box is not available on the HP 48S and HP 28C.

The first two programs, TOREC and TOPOL, will be the subroutines that will be used in a third program, RPCONV.

TOREC: converts polar coordinates to rectangular coordinates

Level 2: θ to y
Level 1: r to x

y = r sin( θ )
x = r cos( θ )

TOPOL: converts rectangular coordinates to polar coordinates

Level 2: y to θ
Level 1: x to r

r = abs(x + yi) = √(x^2 + y^2)
θ = arg(x + yi) = arctan(y/x) where 0 ≤ θ ≤ π (radians) or 0 ≤ θ ≤ 180º (degrees)

The CHOOSE Command

Keystroke sequence for CHOOSE: [LS] [EVAL] (PRG) [NXT] [F5] (IN) [F3] (CHOOS)

Format:

"title of the choose box"
{ {"selection 1" program 1}
{"selection 2" program 2}
...
{"selection n" program n} }
1 CHOOSE


If a selection is made, 1 is returned. If the selection is canceled, 0 is returned. This requires further processing. One way to handle the output of the choose box is:

"title of the choose box"
{ {"selection 1" program 1}
{"selection 2" program 2}
...
{"selection n" program n} }
1 CHOOSE
IF 1 ==
THEN EVAL
ELSE KILL
END


The KILL command stops program execution.

Keystroke sequence for KILL: [LS] [EVAL] (PRG) [NXT] [NXT] [F3] (RUN) [F6] (EVAL)

The Program TOREC

Keystrokes:

[RS] [ + ] ( << >> )
[LS] [EVAL] (PRG) [F1] (STACK) [NXT] [NXT] [F1] (DUP2)

* DUP2 duplicates the contents on Levels 1 and 2
[NXT] [NXT] [F2] (SWAP)
* go the SWAP command from DUP2
[SIN] [ x ] [RS] [ENTER] (→NUM)
* Calculate y = r sin( θ )
[F6] (UNROT)
* rolls down a 3-level stack
[F2] (SWAP) [COS] [ x ] [RS] [ENTER] (→NUM) [ENTER]
* Calculate x = r sin( θ )

[ ' ] [ALPHA] [ALPHA] [COS] (T) [ ' ] (O) [ √ ] (R) [F5] (E) [F3] (C) [ENTER] [STO>]

The completed program:

<< DUP2 SWAP SIN * →NUM UNROT SWAP COS * →NUM >>


The Program TOPOL

Keystrokes:

[RS] [ + ] ( << >> )
[LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[LS] [TOOL] ( i ) [ x ] [ + ]

* Forms the complex number x + yi
[F1] (DUP) [RS] [ ÷ ] (ARG) [RS] [ENTER] (→NUM)
* Calculate θ = arg (x + yi)
[F2] (SWAP) [LS] [ ÷ ] (ABS) [RS] [ENTER] (→NUM) [ENTER]
* Calculate r = abs (x + yi)

[ ' ] [ALPHA] [ALPHA] [COS] (T) [ ' ] (O) [SYMB] (P) [ ' ] (O) [NXT] (L) [ENTER] [STO>]

The completed program:

<< SWAP i * + DUP ARG →NUM SWAP ABS →NUM >>


Now that TOREC and TOPOL are complete, let's do the main program, RPCONV. We made TOREC and TOPOL global programs, so they can be used on their own.

The Program RPCONV

[RS] [ + ] ( << >> )
[RS] [ x ] ( " " )
[ALPHA] [ALPHA] [F3] (C) [LS] [ALPHA] [ ' ] (o) [EVAL] (n) [EEX] (v) [F5] (e) [ √ ] (r) [COS] (t) [F5] (e) [ √ ] (r) [LS] [ALPHA] [ALPHA]

* Titles the choose box "Converter"
[SPC] [LS] [ + ] ( { } )
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [RS] [ 0 ] ( →) [SYMB] (P) [ ' ] (O) [NXT] (L) [F1] (A) [ √ ] (R) [ALPHA]
[ → ] [RS] [ + ] ( << >> ) [ALPHA] [ALPHA] [COS] (T) [ ' ] (O) [SYMB] (P) [ ' ] (O) [NXT] (L) [ALPHA]

* First menu choice, →POLAR. TOPOL is typed.
[ → ] [ → ] [ →] [ → ]
[LS] [ + ] ( { } )
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [RS] [ 0 ] ( → ) [ √ ] (R) [F5] (E) [F3] (C) [COS] (T) [ALPHA]
[ → ] [RS] [ + ] ( << >> ) [ALPHA] [ALPHA] [COS] (T) [ ' ] (O) [ √ ] (R) [F5] (E) [F3] (C) [ALPHA]

* Second menu choice, →RECT. TOREC is typed.
[ → ] [ → ] [ → ] [ → ] [ → ]
1 [LS] [EVAL] (PRG) [NXT] [F4] (IN) [F3] (CHOOS)

* Exits the nested list and the CHOOSE command
[LS] [EVAL] (PRG) [F3] (BRCH) [RS] [F1] (IF)
* Enters the IF-THEN-ELSE-END structure
1 [LS] [EVAL] (PRG) [F3] (TEST) [F1] ( == )
[ ↓ ] [EVAL]
[ ↓ ] [LS] [EVAL] (PRG) [NXT] [NXT] [F3] (RUN) [F6] (KILL)
[ENTER]

* finishes the CHOOSE structure and terminates program entry

[ ' ] [ALPHA] [ALPHA] [ √ ] (R) [SYMB] (P) [F3] (C) [ ' ] (O) [EVAL] (N) [EEX] (V) [ENTER] [STO>]

The completed instructions:

<< "Converter"
{ { "→POLAR" << TOPOL >> }
{ "→RECT" << TOREC >> } }
1 CHOOSE
IF 1 ==
THEN EVAL
ELSE KILL
END >>


Instructions:

Rectangular to Polar Conversion

1. Enter y
2. Press [ENTER]
3. Enter x
4. Run RPCONV
5. Select the →POLAR option

Polar to Rectangular Conversion

1. Enter θ
2. Press [ENTER]
3. Enter r
4. Run RPCONV
5. Select the →RECT option

Examples (the calculator is in Degrees mode):

1. Convert r = 3.8, θ = 30º to rectangular coordinates.

Result: x ≈ 3.2909, y ≈ 1.9000

2. Convert x = 3.2, y = 6.3 to polar coordinates.

Result: r ≈ 7.0661, θ ≈ 63.0723º

Below are screen shots of Example 1.

Next time we will explore system flags.

Have a great day,

Eddie


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

RRL Programming Tutorial - Part 15 - HP 49g+/50g: Strings and Message Boxes

Say it in Style

Welcome to Part 15 of the RPL Programming Tutorial for the HP 49g+ and 50g calculators. Today, we will be working with strings and the MSGBOX command.

MSGBOX

MSGBOX takes a string and displays it as a message box. You can turn in a result into a string (as we will do in the MOPMT program later) and display it in a message box.

The keystroke sequence for MSBOX (49g+/50g) is:
[LS] [EVAL] (PRG) [NXT] [F6] (OUT) [F6] (MSGBO)

Note: The MSGBOX command is not available on the HP 48S or 28C.

String Commands

While entering strings, you can type both upper and lower case letters, insert additional lines, and join multiple strings together.

Upper and Lower Case Letters

Press [ALPHA] once to type in one upper case letter or any of the numbers on the numeric keypad.

Press [LS] [ALPHA] once to type in one lower case letter. The numeric keypad gives some special characters not marked on the keyboard.

Press [RS] [ALPHA] to get access to some Greek characters. The numeric keypad gives some special characters not marked on the keyboard.

Pressing [ALPHA] [ALPHA] turns ALPHA-LOCK on. While on ALPHA-LOCK, pressing [LS] [ALPHA] will switch between upper-case character lock and lower-case character lock. It is a good idea to reset ALPHA-LOCK to upper-case before exiting ALPHA-LOCK.

Carriage Return

Press [RS] [ . ] ←| (it looks something like this) starts a new line in the string.

Joining Strings

Join two strings together by "adding" them. ( [ + ] ).

Level 2: "left string "
Level 1: "right string "

Pressing [ + ] yields:

Level 1: "left string right string "

Some Characters on the HP 49g+/50g

[ALPHA]...
[RS] [F1] α
[RS] [F2] β
[RS] [F3] ∆
[RS] [SIN] σ
[RS] [COS] θ
[LS] [ 0 ] ∞
[RS] [y^x] ^
[RS] [ √ ] √
[RS] [ ÷ ] /
[LS] [ 4 ] $
[LS] [ 5 ] £
[LS] [ 1 ] %
[LS] [ 2 ] ;
[RS] [ 2 ] !
[LS] [ 3 ] #
[RS] [ 3 ] ?
[RS] [ 6 ] angle symbol
[RS] [ 5 ] \
[LS] [ . ] :

Some Characters on the HP 48S/48G

[ALPHA]...
[RS] [1st soft key] α
[RS] [2nd soft key] β
[RS] [3rd soft key] ∆
[RS] [SIN] σ
[RS] [6th soft key] θ
[RS] [CST] ∞
[LS] [ 4 ] $
[LS] [ 5 ] £
[RS] [TAN] %
[RS] [ ÷ ] #
[RS] [ 6 ] degree symbol
[LS] [ 1 ] ==
[RS] [ 1 ] ≠
[LS] [ 2 ] <
[RS] [ 2 ] >
[LS] [ 3 ] ≤
[RS] [ 3 ] ≥
[RS] [SPC] angle symbol


Part 15 will feature two programs: MYMSG and MOPMT.

MYMSG: Types a simple message.

MOPMT: Finds a monthly payment given the number of years, loan amount, and the annual interest rate.

The Program MYMSG

Comments will be italicized, starting with an asterisk *.

[RS] [ x ] (<< >>)
[RS] [ + ] ( " " )
[ALPHA] [ALPHA] [TOOL] (I)

* Starts the string
[LS] [ALPHA]
* Switch to the lower-case alpha lock
[SPC] [F1] (a) [HIST] (m) [SPC] [F1] (a) [SPC] [SIN] (s) [COS] (t) [F1] (a) [ √ ] (r) [RS]
[ . ] (←|)

* [RS] [ . ] is the carriage return
[LS] [ALPHA]
* Switch back to upper-case alpha lock
[ √ ] (R) [SYMB] (P) [NXT] (L) [SPC] [LS] [ALPHA]
* After RPL, switch back to lower-case alpha lock
[SYMB] (p) [ √ ] (r) [ ' ] (o) [APPS] (g) [ √ ] (r) [F1] (a) [HIST] (m) [HIST] (m) [F5] (e) [ √ ] (r) [RS] [ 2 ] (!)
* Finish the string
[LS] [ALPHA] [ALPHA]
* Set the alpha-lock back to upper-case and exit alpha-lock
[ → ] [LS] [EVAL] (PRG) [NXT] [F6] (OUT) [F6] (MSGBO) [ENTER]
* Inserts the MSGBOX command and terminates program entry

[ ' ] [ALPHA] [ALPHA] [HIST] (M) [1/X] (Y) [HIST] (M) [SIN] (S) [APPS] (G) [ENTER] [STO>]

Here is the completed program:

<< " I am a star ←|
RPL programmer!" MSGBOX >>

The Program MOPMT

This program asks for the loan amount, the length of the term in years, and the annual interest rate and returns the payment in a message box.

Formula:

PMT = (A * R) / (1 - (1 + R)^T) where

A = loan amount
T = term in years x 12
R = annual interest rate ÷ 1200

Keystrokes:

[RS] [ + ] ( << >> )
[RS] [ x ] ( " " )
[ALPHA] [ALPHA] [F1] (A) [LS] [ALPHA]

* switch to lower case alpha-lock
[HIST] (m) [ ' ] (o) [TAN] (u) [EVAL] (n) [COS] (t) [LS] [ . ] ( : )
* finish the first string
[LS] [ALPHA] [ALPHA] [ → ]
[LS] [EVAL] (PRG) [NXT] [F5] (IN) [NXT] [F1] (PROMP)

* switch back to upper case alpha-lock and finish the first prompt
[RS] [ x ] ( " " )
[ALPHA] [ALPHA] [COS] (T)
[LS] [ALPHA] [F5] (e) [ √ ] (r) [HIST] (m) [LS] [ . ] ( : )
[LS] [ALPHA] [ALPHA] [ → ] [F1] (PROMP) 12 [ x ]

* Enter the second prompt and multiplied term by 12
[RS] [ x ] ( " " )
[ALPHA] [ALPHA] [ √ ] (R)
[LS] [ALPHA] [F1] (a) [COS] (t) [F5] (e) [LS] [ . ] ( : )
[LS] [ALPHA] [ALPHA] [ →] [F1] (PROMP) 1200 [ ÷ ]

* Enter the third prompt and divided rate by 1200
[RS] [ 0 ] ( → )
[ALPHA] [ALPHA] [F1] (A) [SPC] [COS] (T) [SPC] [ √ ] (R) [ALPHA]

* Store amount, 12*term, rate/1200 in local variables A, T, and R respectively
[RS] [ + ] ( << >> )
[ALPHA] [F1] (A) [SPC] [ALPHA] [ √ ] (R) [ x ]
1 [SPC] 1 [SPC] [ALPHA] [ √ ] (R) [ + ]
[ALPHA] [COS] (T) [y^x] [1/X] [ - ] [ ÷ ]

* Enters the calculation for monthly payment
2 [LS] [SYMB] (MTH) [F5] (REAL) [NXT] [NXT] [F1] (RND)
* Rounds the result to 2 decimal places
[RS] [ x ]
[ALPHA] [ALPHA] [SYMB] (P)
[LS] [ALPHA] [F1] (a) [1/X] (y) [HIST] (m) [F5] (e) [EVAL] (n) [COS] (t) [SPC]
[LS] [ 4 ] ($) [LS] [ALPHA] [ALPHA]

* Build the "Payment $" string. This is the left string, so we need to swap levels 1 and 2
[LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[LS] [EVAL] (PRG) [F5] (TYPE) [F4] (→STR)

* →STR converts numbers and expressions to strings
[ + ]
* Joins the two strings.
[LS] [EVAL] (PRG) [NXT] [F6] (OUT) [F6] (MSGBO) [ENTER]
* Enters the MSGBOX command and terminate the program entry

[ ' ] [ALPHA] [ALPHA] [HIST] (M) [ ' ] (O) [SYMB] (P) [HIST] (M) [COS] (T) [ENTER] [STO>]

The completed program:

<< "Amount:" PROMPT
"Term:" PROMPT 12 *
"Rate:" PROMPT 1200 /
→ A T R
<< A R * 1 1 R + T ^ INV - / 2 RND
"Payment $" SWAP →STR + MSGBOX >> >>


Instructions:

1. Run MOPMT
2. Enter the loan amount and press [LS] [ 0 ] (CONT)
3. Enter the term (in years) and press [LS] [ 0 ] (CONT)
4. Enter the annual rate and press [LS] [ 0 ] (CONT)
5. A message box displays the monthly payment.

Example:

Find the monthly payment on a $256,000, 36-year loan with a given interest rate of 3.7%.

Answer:

Payment
$1073.18

Next time we will work with handy conversions and using choose boxes.

Happy programming,
Eddie.


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

Tuesday, October 18, 2011

RPL Programming Tutorial - Summary - HP 49g+/50g

Summary of Programming Commands

Program

Programs are enclosed with "pointy" brackets ( << >> ). All the programming instructions are included with a set of brackets. These brackets include subroutines.

Local Variables (from the Stack Only)

Keystrokes: << value_n ... value_2 value_1 [RS] 0 ( → ) var_n ... var_2 var_1 [RS] [ + ] (<< >>) to start the main program

Caution: This can be used in only simple cases - such as storing numbers to variables.

A Safe Way to Clean Up the Variables

Keystrokes: [LS] [ + ] ( { } ) [ ' ] enter variable 1 repeat the [ ' ] "var name" as necessary [LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE)

Syntax: { 'var1' 'var2' ... } PURGE

Put the purge instruction at the end of the program.

Force a Numerical Approximation

Keystrokes: [RS] [ENTER] ( → NUM )

Simplify an Expression

Keystroke: [EVAL]

IF-THEN-END Structure

IF condition
THEN do these instructions if the condition is true
END

Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F1] (IF)

IF-THEN-ELSE-END Structure

IF condition
THEN do these instructions if the condition is true
ELSE do these instructions if the condition is false
END

Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [RS] [F1] (IF)

FOR-NEXT Structure

starting-number ending-number FOR counter-variable
instructions to be done, can use the counter-variable
NEXT

Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F4] (FOR)

PROMPT (Prompting for Information)

"prompting string" PROMPT

During execution, the prompt will be at the top of the screen. Enter what the program requires and then press [LS] [ON] (CONT).

Keystrokes: [LS] [EVAL] (PRG) [NXT] [F5] (IN) [NXT] [F1] (PROMP)

Accessing the Catalog

Keystrokes: [RS] [SYMB] (CAT)

Call the Solver

<< equation STEQ 30 MENU >>

STEQ: find STEQ in the catalog
MENU: [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [F1] (MENU)

Operating the solver:

Assign a number to a variable: value [F#] (variable)
To recall the variable's value: [RS] [F#] (variable)
To solve for the desired variable: [LS] [F#] (variable)

You may want to make a separate program to purge the variables used int he program when using STEQ 30 MENU.

WHILE-REPEAT-END Structure

WHILE this condition is met
REPEAT these instructions
END

Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F6] (WHILE)

Temporary Menus Within a Program

{ { "title_1" << program_1 >> }
{ "title_2" << program_2 >> }
...
{ "title_n" << program_n >> } } TMENU

Keystrokes for TMENU: [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [F3] (TMENU)

Alternatively: Hold [LS] while pressing [MODE] [F5] (MENU) [F3] (TMENU)

DO-UNTIL-END Structure

DO these instructions
UNTIL this condition is met
END

Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F5] (DO)

CASE Structure

CASE condition_1 THEN instructions_1 END
condition_2 THEN instructions_2 END
condition_3 THEN instructions_3 END
...
(default instructions - optional) END

CASE-THEN-END-END (Starter):
Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F2] (CASE)

THEN-END (Additional Conditions):
Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [RS] [F2] (CASE)

START-NEXT Structure

This is like the FOR-NEXT structure but without the counter-variable

starting-number ending-number START counter-variable
instructions to be done, can use the counter-variable
NEXT

Keystrokes: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F3] (START)

Subroutines

Enter subroutines at the beginning of the program. Purge it at the end.

Custom Menus

Store to the custom menu (CST): [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [ ' ] [F2] (CST) [STO>]

Alternatively: Hold [LS] and press [MODE] [F4] (MODES) [ ' ] [F2] (CST) [STO>]

This action replaces any previous contents of CST.

Retrieve the custom menu (CST): [LS] [MODE] (CUSTOM)

Message Box

"message string" MSGBOX

Keystrokes: [LS] [EVAL] (PRG) [NXT] [F6] (OUT) [F6] (MSGBO)

Choose Box Structure

"title of the choose box"
{ {"selection 1" program 1}
{"selection 2" program 2}
...
{"selection n" program n} }
1 CHOOSE
IF 1 ==
THEN EVAL
ELSE KILL
END

To Find CHOOSE: [LS] [EVAL] (PRG) [NXT] [F5] (IN) [F3] (CHOOS)

Set and Clear Flags

flag number SF
flag number CF

Get to the Flags Menu:
[LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F3] (FLAG) OR
Hold [LS] press [MODE] [F3] (FLAG)

To set flags : [F1] (SF)
To clear flags: [F2] (CF)

User flags: 1 through 127
System flags: -1 through -127

Flag -13: TVM BGN Mode (Set), TVM END Mode (Clear)
Flag -40: Display Clock (Set), Don't Display Clock (Clear)
Flag -41: 24 Hour Clock (Set), 12 Hour Clock (Clear)
Flag -95: Algebraic Mode (Set), RPN Mode (Clear)
Flag -103: Complex Mode (Set), Real Mode (Clear)
Flag -105: Approximate Mode (Set), Exact Mode (Clear)

PUSH and POP

A very handy pair of programming commands is PUSH and POP. Both commands are found in the catalog.

PUSH: saves the current status of the flags

POP: restores the last saved status of the flags

Some Graphing Commands

XRNG: Sets the left and right boundaries of the plot screen.

left-boundary right-boundary XRNG

YRNG: Sets the bottom and top boundaries of the plot screen.

bottom-boundary top-boundary YRNG

FUNCTION: Sets the calculator to the Function graphing mode (y(x)).

STEQ: Stores an equation, program, or expression into the EQ variable. EQ is used for graphing and/or solving.

INDEP: Sets the variable as independent. The variable is usually X, but can be T, N, Θ, or any other variable.

'var' INDEP

ERASE: Erases the plot screen and gets the calculator ready to draw a fresh, new plot.

DRAW: Has the calculator draw whatever is stored in EQ.

DRAX: Draws the axes.

PICTURE: Switches the calculator to the plot (picture) environment.

Some Algebra and Calculus Commands

Expand

[SYMB] [F1] (ALG) [F1] (EXPAN)

Factor

[SYMB] [F1] (ALG) [F2] (FACTO)

Substitution

Level 2: expression(var)
Level 1: 'var = value'

[SYMB] [F1] (ALG) [F5] (SUBST)

Proper Fraction

[SYMB] [F2] (ARITH) [F5] (PROF)

Derivative (General)

Level 2: expression(var)
Level 1: 'var'

[RS] [COS] ( ∂ )

Integral (General)

Level 4: low limit
Level 3: high limit
Level 2: expression(var)
Level 1: 'var'

[RS] [TAN] ( ∫ )

Sum (General)

Level 4: 'var'
Level 3: low limit
Level 2: high limit
Level 1: expression(var)

[RS] [SIN] ( ∑ )

RPL Programming Tutorial - Part 14 - HP 49g+/50g: Additional Examples

What else can we do?

Plenty. Part 14 will have three programs that illustrate some of what we have learned so far. One point that I really want to stress: with the HP 49g+ and 50g containing over 2,300 commands; so we have not even scratched the surface!

If you have not already, I recommend that you download the HP 50g Advanced User's Reference Manual from Hewlett Packard's website.

HP 48gII/49g+/50g Advanced User's Manual

This manual contains the syntax for ALL of the commands for the 50g and 49g+. The first section also has a section on programming with additional programming examples. It is a really good reference book; I have a copy on my iPad that I can access through iBooks for handy reference.

Today's tutorial will feature three programs:

1. PDM: Test to see if a matrix (with real eigenvalues) is a positive definite matrix.
2. NEWCD: Determines a point in alternate coordinate system with the origin translated (new center) and rotated (in a counterclockwise fashion)
3. SCTR: Scatterplot of data.

The program PDM

A matrix M is said to be a positive definite matrix if M is symmetric and for all non-zero column vectors (z):

z^T M z > 0

Where z^T is a transpose of the vector z.

A simple test is that if:

1. M is symmetric, that is M^T = M, and,
2. The eigenvalues of M are positive,

then M is a positive definite matrix.

Caution: This program gives the error message "> Error: Bad Argument Type" if M has complex valued eigenvalues. Do not conclude anything from the use of PDM if this is encountered.

One of the safest ways to clear errors is to press [ON].


Commands Used:

EGVL: Eigenvalues of a matrix
TRAN: Transpose of a matrix
SIZE: Size of a matrix, vector, or list
∑LIST: Sum of all the elements in a list
==: The comparison does x = y?

[RS] [ + ] (<< >>) [RS] 0 (→) [ALPHA] [F1] (A)
* Store the matrix in local variable A
[RS] [ + ] (<< >>) [LS] [EVAL] (PRG) [F3] (BRCH) [RS] [F1] (IF)
* IF-THEN-ELSE-END structure
[ALPHA] [F1] (A)
[LS] 5 (MATRICES) [NXT] [F1] (EIGEN) [F3] (EGVL)

* EGVL (Eigenvalue command)
[LS] 6 (CONVERT) [F5] (MATRX) [F1] (AXL)
* AXL (List ←→ Vector Command)
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP)
[LS] [EVAL] (PRG) [F6] (LIST) [F1] (ELEM) [F5] (SIZE)

* SIZE command
[LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
0 [RS] [1/X] ( > )
[LS] [SYMB] (MTH) [F3] (LIST) [F2] (∑LIST)

* ∑LIST command
[LS] [EVAL] (PRG) [F4] (TEST) [F1] ( == )
[ALPHA] [F1] (A)
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP)
[L5] 5 (MATRICES) [F2] (OPER) [NXT] [NXT] [F5] (TRAN)

* TRAN - transpose command
[LS] [EVAL] (PRG) [F4] (TEST) [NXT] [F1] (AND) 1 [LS] [NXT] (PREV) [F1] ( == )
* Finish the condition
[ ↓ ] 1 [ ↓ ] 0 [ENTER]
* Finish the program
[ ' ] [ALPHA] [ALPHA] [SYMB] (P) [F4] (D) [HIST] (M) [ENTER] [STO>]

The completed program:

<< → A
<< IF A EGVL AXL DUP SIZE SWAP 0 > ∑LIST == A DUP TRAN == AND 1 ==
THEN 1
ELSE 0
END >> >>


Instructions:

1. Enter the matrix
2. Run PDM

The result is either:

0, the matrix is not positive definite
1, the matrix is positive definite

Examples:

1. The matrix

[[2, 1]
[1, 3]]

returns 1 and is a positive definite matrix.

2. The matrix

[[4, 2, 6]
[3, 0, 7]
[-2, -1, -3]]

has complex eigenvalues and error condition (comparing complex numbers to real numbers) occurs. No conclusion.

3. The matrix

[[2, 1, 0]
[0, 3, 0]
[1, 0, 4]]

returns 0 and is not a positive definite matrix.

Source Used: Richard L. Burden and J. Douglas Faires "Numerical Analysis" 8 ed. Thomson Brooks/Cole 2005

The program NEWCD

This program returns a coordinate in a translated and rotated coordinated system.

Commands Used:

NEG: Negate - used when the user presses [+/-] in a program when the sign is not attached to a number.
R→C: Makes a complex number or ordered pair from two real numbers (Level 2, Level 1)

[RS] [ + ] ( << >> ) [RS] 0 (→)
[ALPHA] [ALPHA] [big X] [ ' ] (O) [NXT] (L) [F4] (D)
[SPC] [1/X] (Y) [ ' ] (O) [NXT] (L) [F4] (D)
[SPC] [big X] [F3] (C) [COS] (T) [ √ ] (R)
[SPC] [1/X] (Y) [F3] (C) [COS] (T) [ √ ] (R)
[SPC] [RS] [COS] (Θ) [ALPHA]

* The theta character (Θ), [RS] [COS] - the character is not printed on the keyboard
[RS] [ + ] ( << >> )
[ALPHA] [ALPHA] [big X] [ ' ] (O) [NXT] (L) [F4] (D)
[SPC] [1/X] (Y) [ ' ] (O) [NXT] (L) [F4] (D) [ALPHA]
[LS] [EVAL] (PRG) [F5] (TYPE) [NXT] [F2] (R→C)

* First of 3 R→C conversions
[ALPHA] [ALPHA] [big X] [F3] (C) [COS] (T) [ √ ] (R)
[SPC] [1/X] (Y) [F3] (C) [COS] (T) [ √ ] (R) [ALPHA]
[F2] (R→C) [ - ]
[ALPHA] [RS] [COS] (Θ)
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP) [COS] [RS] [ENTER] (→NUM)
[F2] (SWAP) [+/-] [SIN] [RS] [ENTER] (→NUM)
[LS] [EVAL] (PRG) [F5] (TYPE) [NXT] [F2] (R→C) [ x ] [ENTER]

* Finish the program
[ ' ] [ALPHA] [ALPHA] [EVAL] (N) [F5] (E) [+/-] (W) [F3] (C) [F4] (D)

The completed program:

<< → XOLD YOLD XCTR YCTR Θ
<< XOLD YOLD R→C XCTR YCTR R→C - Θ DUP COS →NUM SWAP NEG SIN →NUM R→C * >> >>


Instructions:

1. Set up the stack like this:

Level 5: original x coordinate (XOLD)
Level 4: original y coordinate (YOLD)
Level 3: new center - x coordinate (XCTR)
Level 2: new center - y coordinate (YCTR)
Level 1: angle of rotation, counterclockwise (Θ)

2. Run NEWCD

Examples:

All the examples are in degrees mode.

1. Original coordinates: (1,1)
New center: (3,3)
Angle: 45º

Stack:

Level 5: 1
Level 4: 1
Level 3: 3
Level 2: 3
Level 1: 45

Result: (-2.82842712475, 0)

2. Original coordinates: (2, 0)
New center: (0, 0)
Angle: 90º
(pure rotation)

Stack:

Level 5: 2
Level 4: 0
Level 3: 0
Level 2: 0
Level 1: 90

Result: (0, -2)

3. Original coordinates: (4, 2)
New center: (-1, 5)
Angle: 0º
(pure translation)

Stack:

Level 5: 4
Level 4: 2
Level 3: -1
Level 2: 5
Level 1: 0

Result: (5, -3)

The program SCTR

This program takes data from two lists, with a list of x-coordinates listed on Level 2 and a list of corresponding y-coordinates listed on Level 1.

[RS] [ + ] ( << >> )
[RS] 0 (→) [big X] [SPC] [ALPHA] [1/X] (Y)
[RS] [ + ] ( << >> )
1 [SPC] [big X]
[LS] [EVAL] (PRG) [F5] (LIST) [F1] (ELEM) [F5] (SIZE)
[LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F4] (FOR)

* Inserts the FOR-NEXT structure
[ALPHA] [STO] (K) [SPC] [big X] [ALPHA] [STO] (K)
[LS] [EVAL] (PRG) [F6] (LIST) [F1] (ELEM) [F1] (GET)
[ALPHA] [1/X] (Y) [SPC] [ALPHA] [STO] (K) [F1] (GET)
[LS] [EVAL] (PRG) [F5] (TYPE) [NXT] [F2] (R→C)
[LS] [EVAL] (PRG) [NXT] [F2] (PICT) [NXT] [F1] (PIXON) [ ↓ ]

* PIXON turns a pixel on the picture screen
[RS] [SYMB] (CAT) [ALPHA] [F4] (D) find DRAX [F6] (OK)
[RS] [SYMB] (CAT) [ALPHA] [NXT] (L) find LABEL [F6] (OK)

* LABEL labels the axes
[RS] [SYMB] (CAT) [ALPHA] [SYMB] (P) find PICTURE [ENTER]
* Finish the program

[ ' ] [ALPHA] [ALPHA] [SIN] (S) [F3] (C) [COS] (T) [ √ ] (R) [ENTER] [STO>]

The completed program:

<< → X Y
<< 1 X SIZE
FOR K X K GET Y K GET R→C PIXON
NEXT DRAX LABEL PICTURE >> >>


Instructions:

1. Enter a list of x-coordinates.
2. Enter a list of corresponding y-coordinates.
3. Run SCTR. Adjust the plot screen if necessary primary to running SCTR.

Example:

Here is a plot of the following coordinates:

(-4, 2)
(-3, 3)
(-2, 4)
(-1, 1)
(0, 0)
(1, 1)
(2, 4)
(3, 3)
(4, 2)

Stack:

Level 2: {-4, -3, -2, -1, 0, 1, 2, 3, 4}
Level 1: {2, 3, 4, 1, 0 ,1 4, 3, 2}

That concludes Part 14. I hope you are having as much fun learning about RPL program as I am typing the tutorials.


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

RPL Programming Tutorial - Part 13 - HP 49g+/50g: CST Menu and Quadratic Fit

Custom Menus

This may be Part 13 of our RPL tutorial, but it is not going to be an unlucky section (knock on wood). Today, we will create a custom menu and use it for programming.

The calculator contains a custom menu, which can contain as many commands as you want, and whatever commands and programs you want. The custom menu can be changed at any time to fit your needs.

The contents of the menu is a list of contents stored in the variable CST. The custom menu can be accessed by the key sequence [LS] [MODE] (CUSTOM). Best of all, the custom menu can be accessed during program.

To store the custom menu:

1. Have the menu ready at Level 1 on the stack.
2. Press [ ' ] [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [F2] (CST).
3. Press [STO>].

In the program QREG (Quadratic Regression), we will develop a custom menu to assist us.

The QREG takes a two-column matrix, with the first column acting as the x-variable (dependent) and the second column acting as the y-variable (independent) and attempting to find a quadratic fit (see the equation below) of the data by the least-squares method.

y = a + b x + c x^2

The coefficients are found by solving the system of normal equations:

n * a + ∑x * b + ∑x^2 * c = ∑y
∑x * a + ∑x^2 *b + ∑x^3 * c = ∑xy
∑x^2 * a + ∑x^3 * b + ∑x^4 * c = ∑x^2y

Please be aware that QREG is a large program; please take your time with entry. I recommend that you set up the suggested custom menu first - it will save a lot of keystrokes during the entry of the main program.

Source Used: Murray R. Spiegel, Ph. D., John Liu, Ph. D., and Seymour Lipschutz, Ph. D. "Schaum's Outlines: Mathematical Handbook of Formulas and Tables" 2 ed. McGraw-Hill, 1999

The Program QREG

We are going to do things in a little different order in Part 13, starting with the finished program and then let's deal with the keystrokes needed.

<< ->COL DROP SWAP DUP AXL SQ AXL
OVER AXL 3 ^ AXL
3 PICK AXL 4 ^ AXL
5 ROLL
DUP AXL 6 PICK AXL * AXL
2 PICK AXL 6 PICK AXL * AXL
7 COL-> STO∑ CLEAR
N∑
TOT 1 GET
TOT 2 GET
TOT 5 GET
4 ->LIST AXL
TOT 1 GET
TOT 2 GET
TOT 3 GET
TOT 6 GET
4 ->LIST AXL
TOT 2 GET
TOT 3 GET
TOT 4 GET
TOT 7 GET
4 ->LIST AXL
3 ROW-> RREF 4 COL- >>


Note that the commands AXL, STO∑, TOT, PICK, GET, and &#8594LIST appear frequently. Let's make a custom menu with these six commands before we start programming QREG.

Setting Up the Custom Menu

[LS] [ + ] ( { } )
* Start the list
[LS] 6 [F5] (MATRX) [F1] (AXL)
* The first command AXL
[RS] [SYMB] (CAT) [ALPHA] [SIN] (S) find STO∑ [F6] (OK)
* The second command STO∑
[RS] [SYMB] (CAT) [ALPHA] [COS] (T) find TOT [F6] (OK)
* The third command TOT
[LS] [EVAL] (PRG) [F1] (STACK) [NXT] [F3] (PICK)
* The fourth command PICK
[LS] [EVAL] (PRG) [F6] (LIST) [F1] (ELEM) [F1] (GET)
* The fifth command GET
[NXT] [F6] (LIST) [F4] (->LIST)
* The sixth command &#8594LIST, going from the current menu
[LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [ ' ] [F2] (CST) [ENTER] [STO>]
* Stores the custom menu.

The commands in the custom menu:

AXL: a toggle. AXL changes a list to a vector. AXL changes a vector to a list.
STO∑: stores a matrix into the variable ∑DAT. ∑DAT is used for statistical analysis.
TOT: Totals each column of ∑DAT.
PICK: Picks a certain level from the stack. Syntax: n PICK
GET: Gets or retrieves an element of a list, vector, or matrix. Syntax: list n GET
->LIST: Takes n levels from the stack and creates a list. Syntax: n &#8594LIST

The custom menu will set up with the soft keys:

[F1] (AXL)
[F2] (STO∑)
[F3] (TOT)
[F4] (PICK)
[F5] (GET)
[F6] (->LIST)

Other Commands Used

->COL: Matrix to Columns command. Extracts a column from a matrix.
COL->: Columns to Matrix command. Transfers a given set of column vectors to a matrix.
ROW->: Rows to Matrix command. Creates a matrix from a given set of row vectors.
RREF: Calculates the row-reduced-echelon form of a matrix.


Setting up ∑DAT

In order to get ∑x, ∑x^2, ∑x^3, ∑x^4, ∑y, ∑xy, and ∑x^2y, the statistics matrix ∑DAT is set up as:

Column 1: x-data
Column 2: x-data^2
Column 3: x-data^3
Column 4: x-data^4
Column 5: y-data
Column 6: x-data * y-data
Column 7: x-data^2 * y-data

TOT will be used to extract the sums of the columns.

Keystrokes - Main Program (QREG)

This assumes that you have the custom menu set up as discussed above.


[RS] [ + ] (<< >>)
[LS] 5 (MATRICES) [F1] (CREAT) [F1] (COL) [F1] (->COL)
[LS] [EVAL] (PRG) [F1] (STACK) [F3] (DROP) [F2] (SWAP) [F1] (DUP)
[LS] [MODE] (CUSTOM) [F1] (AXL) [LS] [ √ ] (x^2) [F1] (AXL)

* First of many instances the custom menu is used - building the x-data^2 column
[LS] [EVAL] (PRG) [F1] (STACK) [F4] (OVER)
[LS] [MODE] (CUSTOM) [F1] (AXL) 3 [y^x] [F1] (AXL)

* Building the x-data^3 column
3 [F4] (PICK) [F1] (AXL) 4 [y^x] [F1] (AXL)
* Building the x-data^4 column
5 [LS] [EVAL] (PRG) [F1] (STACK) [NXT] [F1] (ROLL)
[LS] [NXT] (PREV)

* PREV goes to the previous page of a menu
[F1] (DUP)
[LS] [MODE] (CUSTOM) [F1] (AXL) 6 [F4] (PICK) [F1] (AXL) [ x ] [F1] (AXL)

* Building the x-data * y-data and x-data^2 * y-data columns 

2 [LS] [MODE] (CUSTOM) [F4] (PICK)
[F1] (AXL) 6 [F4] (PICK) [F1] (AXL) [ x ] [F1] (AXL)
* Thanks to Alan Jones for pointing out to me that I was missing this point in the instruction. (added 12/30/2015)

7 [LS] 5 (MATRICES) [F1] (CREAT) [F1] (COL) [F2] (COL&#8594)
* Build the matrix from the 7 column vectors
[LS] [MODE] (CUSTOM) [F2] (STO∑) [RS] [backspace] (CLEAR)
* Stores the matrix to ∑DAT and clears the stack - the Custom menu (should be) is active
[RS] [SYMB] (CAT) [ALPHA] [EVAL] (N) find N∑ [F6] (OK)
[F3] (TOT) 1 [F5] (GET)
[F3] (TOT) 2 [F5] (GET)
[F3] (TOT) 5 [F5] (GET)
4 [F6] (->LIST) [F1] (AXL)

* First row of the normal equations is formed. The next two equations are formed in the similar way.
[F3] (TOT) 1 [F5] (GET)
[F3] (TOT) 2 [F5] (GET)
[F3] (TOT) 3 [F5] (GET)
[F3] (TOT) 6 [F5] (GET)
4 [F6] (->LIST) [F1] (AXL)

* Second normal equation
[F3] (TOT) 2 [F5] (GET)
[F3] (TOT) 3 [F5] (GET)
[F3] (TOT) 4 [F5] (GET)
[F3] (TOT) 7 [F5] (GET)
4 [F6] (->LIST) [F1] (AXL)

* The third and final normal equation
3 [LS] 5 (MATRICES) [F1] (CREAT) [F2] (ROW) [F2] (ROW->)
* Form the matrix from the three row vectors
[LS] 5 (MATRICES) [F5] (LIN S) [F4] (RREF)
* Row-reduced echelon form
4 [LS] 5 (MATRICES) [F1] (CREAT) [F1] (COL) [F4] (COL-) [ENTER]
* Extract the column [a, b, c] and terminates program entry.
[ ' ] [ALPHA] [ALPHA] [y^x] (Q) [ √ ] (R) [F5] (E) [APPS] (G) [ENTER] [STO>]

Instructions:

1. Enter a two column matrix. One way to enter matrices is to use the calculator's matrix writer by pressing the sequence [LS] [ ' ] (MTRW). To enter the matrix, press [ENTER] after entering the last element. To cancel matrix entry, press [ON].
2. Run QREG.

Results:

Level 2: Matrix
Level 1: Coefficients Vector

Coefficients vector [ a b c ] represents:

y = a + b * x + c * x^2

If the matrix is an identity matrix of size 3 ([[1,0,0][0,1,0][0,0,1]]), then a definite solution has been found.
Example:

Fit a quadratic curve to this data:

(1, 1)
(2, 3.6)
(3, 8.9)
(4, 17)
(5, 26.5)

So the matrix that is needed is:

[[1 1]
[2 3.6]
[3 8.9]
[4 17]
[5 26.5]]

To four decimal places QREG returns:

Level 2: [[1 0 0][0 1 0][0 0 1]]
Level 1: [.3800 -.6743 1.1857]

That means the quadratic curve that best fits the data is:

y ≈ 0.38 - 0.6743x + 1.1857x^2

Have fun fitting other sets of data to quadratic equations. Next time I will present additional programming examples. Keep on programming, Eddie!

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

RPL Programming Tutorial - Part 12 - HP 49g+/50g: Subroutines and the START Loop

Subroutines

Welcome to Part 12 of the RPL Tutorial. In Part 12, we will cover subroutines. A subroutine is a named routine defined in the program, which is saved for later use. the subroutine is called whenever the need arises.

One way to approach subroutines is to type and store the subroutines at the beginning at the program. Unless the user desires to store the subroutine permanently, the subroutine must be purged at the end of the program. Here is one template for a program using a subroutine:

<< << subroutine >> 'SUB1' STO
main program
'SUB1' PURGE >>


Using two or more subroutines:

<< < subroutine1 >> 'SUB1' STO
<< subroutine2 >> 'SUB2' STO
...
main program
...
{'SUB1' 'SUB2' ... } PURGE >>


START-NEXT Structure

The START-NEXT structure is like the FOR-NEXT structure, except that the START-NEXT structure does not use a counter. A structure looks like this:

<< start stop START commands NEXT >>

Keystroke sequence: [LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F3] (START)

The program presented in Part 12 will illustrate using a subroutine and a START-NEXT structure.

Building a list of random numbers

In this program, we are going to pick d integers from low (l) to high (h) - allowing the choices to repeat.

The program uses the subroutine named SUB1:

<< H L - RAND x IP L + >>

SUB1 will be called up in the START-NEXT loop.

The other variables used in the program are:

L = low number,
H = high number, and
D = # of draws

To build the list, the stack is cleared, allowing the program to fill it with draws. Once the draws are complete, DEPTH →LIST will be used to create the list.

The Program SAMP

[RS] [ + ] ( << >> )
[RS] [ + ] ( << >> )
[ALPHA] [MODE] (H) [SPC] [ALPHA] [NXT] (L) [ - ]
[LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F4] (RAND) [ x ]
[LS] [SYMB] (MTH) [F5] (REAL) [NXT] [F5] (IP) [ALPHA] [NXT] (L) [ + ] [ ↓ ]
[ ' ] [ALPHA] [ALPHA] [SIN] (S) [TAN] (U) [F2] (B) 1 [ALPHA] [ → ]
[STO>]

* Enters are stores the subroutine SUB1
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [NXT] (L) [ ' ] (O) [+/-] (W) [RS] 3 (?)
* [ALPHA] [RS] 3 sequence gives the question mark character, the ? is not marked on the keyboard
[ALPHA] [ → ] [LS] [EVAL] (PRG) [NXT] [F5] (IN) [NXT] [F1] (PROMP) [ ' ] [ALPHA] [NXT] (L) [ → ] [STO>]
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [MODE] (H) [TOOL] (I) [APPS] (G) [MODE] (H) [RS] 3 (?) [ALPHA] [ → ] [F1] (PROMP) [ ' ] [ALPHA] [MODE] (H) [ → ] [STO>]
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [LS] 3 (#) [SPC] [F4] (D) [ √ ] (R) [F1] (A) [+/-] (W) [SIN] (S) [RS] 3 (?) [ALPHA] [ → ] [F1] (PROMP) [ ' ] [ALPHA] [F4] (D) [ → ] [STO>] [RS] [backspace] (CLEAR)

* Enters the prompts for H, L, and D.
1 [SPC] [ALPHA] [F4] (D)
[LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F3] (START)

* Inserts the START-NEXT structure
[ALPHA] [ALPHA] [SIN] (S) [TAN] (U) [F2] (B) 1 [ALPHA]
* Calls the subroutine SUB1
[ ↓ ]
[LS] [EVAL] (PRG) [F1] (STACK) [NXT] [F6] (DEPTH)
[LS] [EVAL] (PRG) [F6] (LIST) [F4] ( →LIST )

* Turns the stack into a list with DEPTH →LIST
[LS] [ + ] ( { } )
[ ' ] [ALPHA] [ALPHA] [SIN] (S) [TAN] (U) [F2] (B) 1 [ALPHA] [ → ]
[SPC] [ ' ] [ALPHA] [MODE] (H) [ → ]
[SPC] [ ' ] [ALPHA] [NXT] (L) [ → ]
[SPC] [ ' ] [ALPHA] [F4] (D) [ → ] [ → ] [ → ]
[LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE) [ENTER]

* Clean up and entry termination

[ ' ] [ALPHA] [ALPHA] [SIN] (S) [F1] (A) [HIST] (M) [SYMB] (P) [ENTER] [STO>]

The complete program:

<<
<< H L - RAND x IP L + >> 'SUB1' STO
"LOW?" PROMPT 'L' STO
"HIGH?" PROMPT 'H' STO
"# DRAWS?" PROMPT 'D' STO
CLEAR
1 D START SUB1 NEXT
DEPTH →LIST { SUB1 H L D } PURGE >>


Instructions:

1. Run SAMP
2. Enter the low number at the "LOW?" prompt, press [LS] [ON] (CONT)
3. Enter the high number at the "HIGH?" prompt, press [LS] [ON] (CONT)
4. Enter the number of draws at the "# OF DRAWS?" prompt, press [LS] [ON] (CONT)
5. Obtain a list. Use [HIST] [F2] (VIEW) to see the list.

Example:

1. Draw 6 numbers from 100 to 999. A result may be:

{361, 779, 156, 295, 349, 382}

2. Draw 12 2 digit numbers (10 to 99). A result may be:

{52, 63, 83, 76, 52, 54, 71, 47, 70, 16, 23, 41}

This concludes Part 12 of our tutorial. Up next we will make a custom menu and use it to help make programming easier. As always, thank you visiting - Eddie


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

RPL Programming Tutorial - Part 11 - HP 49g+/50g: The CASE Structure and Labeling Results

In this case, do this; in that case, do that...

Part 11 of our tutorial will cover the CASE structure, which is really the IF-THEN-ELSE-END structure repeated more than one time.

The CASE structure looks like this:

CASE test_1 THEN commands if test_1 is true END
test_2 THEN commands if test_2 is true END
test_3 THEN commands if test_3 is true END
...
commands if none of the tests are true (default, optional) END


The default commands are optional. If there is no default commands, the structure ends without any action. Note that CASE is only needed once, and there must always be a final END to this structure. CASE is found in the PRG-BRCH menu.

Key [LS] [F2] (CASE) to get:

CASE
THEN
END
END

Use this key sequence as a starter.

Key [RS] [F2] (CASE) to get:

THEN
END

Use this key sequence to add additional cases. Remember only one CASE is needed per structure.

Labeling Results

Sometimes we want to label results. One way to label results is the relatively easy command →TAG. This command can be accessed by the keystroke sequence:

[LS] [EVAL] (PRG) [F5] (TYPE) [F5] (→TAG)

→TAG takes the result from Level 2 and a string (your label) from Level 1. An example would be:

2: 3.14159265359
1: "PI"

Executing →TAG returns:

1: PI:3.14159265359

→TAG automatically adds a colon ( : ) to the label. A tagged object (number) can be used in any calculation like normal. However once a calculation is executed, the tag is lost.

What's my tax?

To illustrate the CASE structure, let's analyze and calculate how much income tax liability taxpayers have in a given state. The state takes the taxable income of a taxpayer and uses this graduated schedule to determine payment:

$0 - $14,999: 5% of taxable income
$15,000 - $99,999: 7% of taxable income exceeding $14,999 plus $1,050
$100,000 and above: 9% of taxable income exceeding $99,999 plus $7,000

Here the tax preparer wants to know how much is the tax liability. In addition, the preparer wants to label both the income and tax liability.

The CASE structure is set up like this:

Case 1: If income < 15,000, then calculate income * 5%
Case 2: If 15,000 ≤ income < 100,000, then calculate income above 14,999 * 7% + 1050, We'll break up the condition for Case 2 this way: 15,000 ≤ income AND income < 100,000.
Otherwise: Calculate income above 99,999 * 9% + 7000

The Program INTAX

[RS] [ + ] (<< >>)
[LS] [SYMB] (MTH) [F5] (REAL) 0 [NXT] [NXT] [F1] (RND)

* Rounds the entry to the nearest integer (number 0 RND)
[LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F2] (CASE)
* The primary CASE-THEN-END-END structure
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP)
15000 [RS] [big X] ( < )

* First condition: income < 15,000
[ ↓ ] [F1] (DUP) .05 [ x ]
* First calculation
[ ↓ ]
[F1] (DUP) [F1] (DUP) 100000 [RS] [big X] ( < ) [F2] (SWAP) 15000 [LS] [1/X] ( ≥ )
[LS] [EVAL] (PRG) [F4] (TEST) [NXT] [F1] (AND)
[LS] [EVAL] (PRG) [F3] (BRCH) [RS] [F2] (CASE)

* Second condition: 15,000 ≤ income < 100,000 - connect two required conditions with AND
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP) 14999 [ - ] .07 [ x ] 1050 [ + ]
* Second calculation
[F1] (DUP) 99999 [ - ] .09 [ x ] 7000 [ + ]
* Default calculation
[ ↓ ]
* Exits the CASE structure
0 [LS] [SYMB] (MTH) [F5] (REAL) [NXT] [NXT] [F1] (RND)
* Rounds the final result to the nearest integer
[RS] [ x ] ( " " ) [ALPHA] [ALPHA] [COS] (T) [F1] (A) [big X] [ALPHA] [ → ]
[LS] [EVAL] (PRG) [F5] (TYPE) [F5] (→TAG)

* Apply the tag on the income tax.
[LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP)
[RS] [ x ] [ALPHA] [ALPHA] [TOOL] (I) [EVAL] (N) [F3] (C) [ ' ] (O) [HIST] (M) [F5] (E) [ALPHA] [ → ] [LS] [EVAL] (PRG) [F5] (TYPE) [F5] (→TAG)

* Apply the tag on the income.
[LS] [EVAL] (PRG) [F1] (STACK) [F2] (SWAP) [ENTER]
* Finish the program

[ ' ] [ALPHA] [ALPHA] [TOOL] (I) [EVAL] (N) [COS] (T) [F1] (A) [big X] [ENTER] [STO>]

The completed program:

<< 0 RND
CASE DUP 15000 < THEN DUP .05 * END
DUP DUP 100000 < SWAP 15000 ≥ AND THEN
DUP 14999 - .07 * 1050 + END
DUP 99999 - .09 * 7000 + END
0 RND "TAX" →TAG SWAP "INCOME" →TAG SWAP >>


Instructions:

1. Enter the taxable income.
2. Run INTAX

Examples:

1. Income: $13,000; Tax: $650
2. Income: $15,000; Tax: $1,050
3. Income: $50,000; Tax: $3,500
4. Income: $100,000; Tax: $7,000
5. Income: $150,000; Tax: $11,500

This wraps it up for Part 11 - on to Part 12 where we work with a subroutine. Until next time, Eddie.

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

RPL Programming Tutorial - Part 10 - HP 49g+/50g: The DO Loop

Do It Until It's Done!

Welcome to the third week of my RPL tutorials for the HP 49g+ and 50g Hewlett Packard graphing calculators. We will start this batch of tutorials with Part 10: the Do Loop.

The DO-UNTIL-END loop structure works like the WHILE-REPEAT-END loop structure except instead of repeating a bunch of designated commands while a certain condition is met, this time we are repeating a bunch of designated commands until a condition is met.

A DO-UNTIL-END structure looks like this:

DO commands
UNTIL this condition is met
END


Key sequence from the PRG-BRCH menu:

[LS] [F5] (DO)

Let's illustrate a use of a DO-UNTIL-END structure with a simple program: have the calculator generate a bunch of random numbers until the sum of 1 is reached.

It's a new week - so here is a reminder of how I label shift keys:

[RS] is the right shift key, 2nd key up from the ON button on the left side of the keyboard. [RS] is red on the 49g+ and orange on the 50g.

[LS] is the left shift key, 3rd key up from the ON button on the left side of the keyboard. [LS] is green on the 49g+ and white on the 50g.

[ALPHA] is the 4th key up from the ON button on the left side of the keyboard. On both the 49g+ and the 50g, the key is yellow. Pressing [ALPHA] twice puts the calculator in ALPHA-LOCK mode.

[big X] is the "X" key on the 4th row from the bottom, 3rd from the left. This is so I distinguish X from the times key ([ x ]).

Finally, the soft keys labeled F1 - F6 are on the top row.

Add Random Numbers until I get at least 1

This program will keep adding random numbers until the sum exceeds one.

The Program RAND1

Comments are italicized beginning with an asterisk. Here we go!

[RS] [ + ]
[LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F4] (RAND)

* Inserts the first random number. RAND always enters numbers between 0 and 1.
[LS] [EVAL] (PRG) [F3] (BRCH)
[LS] [F5] (DO)

* Inserts the DO-UNTIL-END structure
[LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F4] (RAND)
[ + ] [ ↓ ]

* Enter the commands that are to be repeated (RAND + )
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP)
1 [LS] [1/X] ≥

* Enters the condition (sum≥1)
[ENTER]
* Terminates program entry

[ ' ] [ALPHA] [ALPHA] [ √ ] (R) [F1] (A) [EVAL] (N) [F4] (D) [ENTER] [STO>]

The completed program:

<< RAND
DO RAND +
UNTIL DUP 1 ≥
END >>


Instructions:

Just run RAND1.

Examples of some results you might get: 1.46211570675, 1.12775622211, 1.50610262525

That wraps up Part 10 of the RPL Tutorial Series. Next time, we'll look at the CASE structure. See you then!

Eddie

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

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.

RPL Programming Tutorial - Part 8 - HP 49g+/50g: The WHILE Loop

While We Are Here...

Welcome to Part 8 of the RPL Programming Tutorial. Today, we will cover the WHILE-REPEAT-END programming structure. This structure is similar to the WHILE-WEND programming structure in BASIC. In this loop certain commands are repeated while a condition is true.

The WHILE-REPEAT-END structure looks like this:

WHILE this condition is met
REPEAT these instructions
END


The Program DBY2

This program takes the absolute number from the stack. As long as the number is greater than 1, the program keeps dividing the number by 2.

Note the use of DUP in this program. The DUP (Duplicate) command duplicates the contents of Level 1. It is necessary because tests consume the contents of levels 2 and 1.

[RS] [ + ] (<< >>)
[LS] [ ÷ ]
[LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP)

* The DUP command
[LS] [EVAL] (PRG) [F3] (BRCH) [LS] [F6] (WHILE)
* Enters the WHILE-REPEAT-END structure
1 [LS] [1/X] ≥
* Enters the while condition
[ &darr ] 2 [ ÷ ] [LS] [EVAL] (PRG) [F1] (STACK) [F1] (DUP)
* Enters the loop instructions
[EVAL] [ENTER]
* Simplifies the number and terminates program entry

[ ' ] [ALPHA] [ALPHA] [F4] (D) [F2] (B) [1/X] (Y) 2 [ENTER] [STO>]

The Complete Program:

<< ABS DUP
WHILE 1 ≥
REPEAT 2 / DUP
END EVAL >>


Instructions:

1. Enter a number.
2. Run DBY2.

Examples:

10 returns 5/8
96 returns 3/4
-105 returns 105/128

This concludes Part 8 of our tutorial. Next time, we will create custom menus. It's going to be a lot of fun! Until next time, Eddie.


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

RPL Programming Tutorial - Part 7 - HP 49g+/50g: Solver

How Do You Solve This Thing Again?

Welcome to Part 7 of the RPL Tutorials for the HP 49g+ and 50g calculators. Today, we are going to call the calculator's solver in a program. It is a fairly simple process:

1. The first step is setup the equation. We can set up the equation either as an Algebraic object or an RPN program.
2. We follow the equation by the commands STEQ 30 MENU. STEQ (Store Equation) stores the equation for solving purposes. The commands 30 MENU brings up a soft-key menu solver. The soft-key menu solver is a classic solver that was used in the HP 48S and HP 48G series.

In this program, we will use the classic solver to expand the capability of the UTPN (Upper Tail Probability Normal Distribution) function.

UTPN

The UTPN function returns the upper tail area (p) of the normal distribution given the mean (µ), variance (v), and point on the curve (x).

Mathematically,

p = (√2 π v) ^ -1 * ∫(x, ∞, e^( -(t - µ)^2 / (2v) ), t)

In a standard normal distribution, µ = 0 and v = 1, so the equation simplifies to:

p = (√2 π) ^ -1 * ∫(x, ∞, e^(-t^2/2), t)

where x = (z - µ)/v

A Note Using 30 MENU

The variables using 30 MENU are global. Therefore, it may be a wise idea to purge each of the variables after use. In this tutorial, we will create a second program to clean up the variables - this program is optional.

The Program NSLVR (Normal Distribution Solver)

Comments will be italicized, starting with an asterisk.

Variables used:
M = the mean
V = the variance
X = the point
P = the upper tail area, probability, -1 ≤ p ≤ 1

[RS] [ + ] (<< >>)
[RS] [ + ] (<< >>)

* To use an RPN string in enter an equation, a second set of program brackets is necessary.
[ALPHA] [ALPHA] [HIST] (M) [SPC] [EEX] (V) [SPC] [big X] [SPC] [ALPHA]
[LS] [SYMB] (MTH) [NXT] [F1] (PROB) [NXT] [F3] (UTPN)
[ALPHA] [SYMB] (P) [SPC] [ - ]

* Enter the equation UTPN(M,V,X) = P
[ &darr ] [RS] [SYMB] (CAT) [ALPHA] [SIN] (S) find STEQ
30 [LS] [EVAL] (PRG) [NXT] [F4] (MODES) [F5] (MENU) [F1] (MENU)

* Enter STEQ 30 MENU
[ENTER]
* Terminate program entry

[ ' ] [ALPHA] [ALPHA] [EVAL] (N) [SIN] (S) [NXT] (L) [EEX] (V) [ √ ] (R) [ENTER] [STO>]

The completed program:

<<
<< M V X UTPN - >>
STEQ 30 MENU >>


(Optional) The program NSCLR (Normal Distribution Solver Cleaner)

[RS] [ + ] (<< >>)
[LS] [ + ] ( { } )

* Start a list
[ALPHA] [ALPHA] [HIST] (M) [SPC] [EEX] (V) [SPC] [big X] [SPC] [SYMB] (P) [ALPHA] [ &rarr ] [LS] [EVAL] (PRG) [F2] (MEM) [F1] (PURGE)
* Enters the variables used in NSLVR and purges them
[SPC] [RS] [ x ] [ALPHA] [ALPHA] [F4] (D) [ ' ] (O) [EVAL] (N) [F5] (E) [ENTER]
* Inserts a "DONE" message and ends program entry.

[ ' ] [ALPHA] [ALPHA] [EVAL] (N) [SIN] (S) [F3] (C) [NXT] (L) [ √ ] (R) [ENTER] [STO>]

The completed program:

<< { M V X P } PURGE "DONE" >>

Instructions for NSLVR:

To solve for upper tail area (P):
1. Run NSLVR.
2. Enter M, press [F1]
3. Enter V, press [F2]
4. Enter X, press [F3]
5. Press [LS] [F4] (P)

Examples:

1. Find the upper tail area with M = 0, V = 1, and X = 1.

Keystrokes: 0 [F1] (M) 1 [F2] (V) 1 [F3] (X) [LS] [F4] (P)

Result: 0.158655253931

2. Find the area between X = 5 and X = 15, using M = 10 and V = 5.8.

Keystrokes: 10 [F1] (M) 5.8 [F2] (V) 15 [F3] (X) [LS] [F4] (P)
* Area to the right of X = 15 (15 to ∞)
5 [F3] (X) [LS] [F4] (P)
* Area to the right of X = 5 (5 to ∞)
[LS] [ &rarr ] [ - ]
* Subtract the area above X = 5

Result: 0.962118717684

3. Find the lower tail area with M = 0, V = 1, and X = 0.

Keystrokes: 0 [F1] (M) 1 [F2] (V) 0 [F3] (X) [LS] [F4] (P)

Result: 0.5

To solve for the point (X): [Inverse Normal Distribution Function]
1. Run NSLVR.
2. Enter M, press [F1]
3. Enter V, press [F2]
4. Enter P, press [F4]
5. Press [LS] [F3] (X)

Examples:

1. Find X when the lower tail probability is P = 0.95. Use M = 0 and V = 1.

Keystrokes: 0 [F1] (M) 1 [F2] (V) 1 [ENTER] .95 [ - ] [F4] (P) [LS] [F3] (X)

Result: 1.64485362695

Remember: P is the upper tail area.

2. With M = 44.2 and V = 1.7, find the point where the upper tail probability is 55% (P = 0.55).

Keystrokes: 44.2 [F1] (M) 1.7 [F2] (V) .55 [F4] (P) [LS] [F3] (X)

Result: 44.0361576491

To clean up: Run NSCLR

That wraps up Part 7 of our Tutorial. Please join us next time while we explore the WHILE-REPEAT-END structure. So long for now, Eddie.

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




RPL Programming Tutorial - Part 6 - HP 49g+/50g: Algebra & Calculus

Algebra & Calculus

Welcome to Part 6. Today we are going to take a break from programming and learn more about some of the cool stuff we can do with algebraic objects. Part 5 gave an introduction to algebraic objects.

Recall that algebraic objects are functions or expressions that are enclosed in single quotes. Examples include:

'A=B+C'
'√5'
'SIN(X+π/2)'

Expressions can usually be entered in one of three ways:

1. As a string of RPN commands
2. As an algebraic expression entered between single quotes
3. From the Equation Writer ([RS] [ ' ] (EQW))

When programming, generally only the first two methods are available.

Set Up: ** HP 49g+ and 50g **

For Part 6, we will use X as the CAS variable. You can tell if it is by the 'X' indicator at the top of the screen. If it doesn't (i.e. it reads 'T' or 'N', or something else), follow the procedure below.

To set X as the CAS variable:
1. Press [MODE].
2. Press [F3] (CAS).
3. Type [ ' ] [big X] at the Indep Var prompt. Press [F6] (OK) twice.

To clear X:
1. Type [ ' ] [big X] [ENTER].
2. Press [TOOLS] [F5] (PURGE).

Now we're ready to go!

The important EVAL

The [EVAL] key simplifies expressions. Use this key to force the calculator to simplify the expressions (and make them look nice).

Comma

Sometimes commands have more than one argument. If you are entering commands with multiple required arguments, use a comma. The keystroke for a comma is [RS] [SPC] ( , ).

Note: [big X] is located on the 5th rows of keys up from the bottom. I will use this to distinguish the X character from the times key [ x ].

Some Common Algebra CAS Commands

EXPAND: Rewrites algebraic expressions by distributing powers over sums and multiplication over addition and subtraction.

Keystrokes: [SYMB] [F1] (ALG) [F1] (EXPAN)

Example: Expand (x + 2)^5.

By RPN Entry: [big X] [ENTER] 2 [ + ] 5 [y^x] [SYMB] [F1] (ALG) [F1] (EXPAN) [EVAL]

By Algebraic Object: [ ' ] [LS] [ - ] (parenthesis) [big X] [ + ] 2 [ &rarr ] [y^x] 5 [ENTER] [SYMB] [F1] (ALG) [F1] (EXPAN) [EVAL]

Result: x^5 + 10x^4 + 40x^3 + 80x^2 + 80x + 32
(Use [HIST] [F2] (VIEW) or [ &uarr ] [F2] (VIEW) to see the entire result as needed.)

FACTOR: Attempts to factor the expression.

Keystrokes: [SYMB] [F1] (ALG) [F2] (FACTO)

Example: Factor x^2 + 5x + 6.

By RPN Entry: [big X] [ENTER] [ENTER] [LS] [ √ ] (x^2) [LS] [ &rarr ] (SWAP) 5 [ x ] [ + ] 6 [ + ] [EVAL] [SYMB] [F1] (ALG) [F2] (FACTO)

By Algebraic Object: [ ' ] [big X] [y^x] 2 [ + ] 5 [ x ] [big X] [ + ] 6 [ENTER] [SYMB] [F1] (ALG) [F2] (FACTO)

Result: (x + 2)(x + 3)

SUBST: Substitutes an expression for a given variable.

Stack Setup:
Level 2: expression
Level 1: 'variable = value'

Keystrokes: [SYMB] [F1] (ALG) [F5] (SUBST)

Example: Given the function f(x) = x^2 + e^-x, find a numerical approximation of f(1). Remember, you find numeric approximations by the [RS] [ENTER] (&rarr NUM) sequence.

By RPN Entry: [big X] [LS] [ √ ] (x^2) [big X] [+/-] [LS] [y^x] (e^x) [ + ] [big X] [ENTER] 1 [RS] [+/-] (=) [SYMB] [F1] (ALG) [F5] (SUBST) [RS] [ENTER] (&rarr NUM)

By Algebriac Object: [ ' ] [big X] [y^x] 2 [ + ] [LS] [y^x] (e^x) [+/-] [big X] [ENTER]
[ ' ] [big X] [RS] [+/-] (=) 1 [ENTER] [SYMB] [F1] (ALG) [F5] (SUBST) [RS] [ENTER] (&rarr NUM)


Result: 1.36787944117

PROPFRAC: Gives the proper fraction of a rational expression p(x)/q(x). p(x) and q(x) are not necessarily polynomials.

Keystrokes: [SYMB] [F2] (ARITH) [F5] (PROPF)

Example: Find the proper fraction of (x^3 + 2x + 1)/(x - 5).

By RPN Entry: [big X] [ENTER] 3 [y^x] 2 [ENTER] [big X] [ x ] [ + ] 1 [ + ] * (numerator) [big X] [ENTER] 5 [ - ] * (demoniator) [ ÷ ] [SYMB] [F2] (ARITH) [F5] (PROPF)

By Algebriac Object:
Note: We can divide objects (and use other mathematical operators), so let's enter the numerator and denominator separately. Obviously, you can use parenthesis and enter the entire expression as one.
[ ' ] [big X] [y^x] 3 [ + ] 2 [ x ] [big X] [ + ] 1 [ENTER]
[ ' ] [big X] [ - ] 5 [ENTER]
[ ÷ ] [SYMB] [F2] (ARITH) [F5] (PROPF)


Result: x^2 + 5x + 27 + 136/(x-5)

Some Common Calculus CAS Commands

DERVX: First derivative of any expression where X is the independent variable (assumes you have X set up as the Independent Variable)

Keystrokes: [SYMB] [F3] (CALC) [F2] (DERVX)

Example: Find ∂/∂x sin(x^2 + 1)

By RPN: [big X] [LS] [ √ ] (x^2) 1 [ + ] [SIN] [SYMB] [F3] (CALC) [F2] (DERVX) [EVAL]

By Algebraic Object: [ ' ] [SIN] [big X] [y^x] 2 [ + ] 1 [ENTER] [SYMB] [F3] (CALC) [F2] (DERVX) [EVAL]

Result: 2x cos(x^2 + 1)

: First Derivative to any variable.

Stack Setup:
Level 2: Expression
Level 1: 'Variable'

Keystrokes: [RS] [COS] ( ∂ )

As an algebraic object: ' ∂variable(expression) ' Use [EVAL] to evaluate.

Example: Find ∂/∂T cos(T^2 + π/T)

Get the stack to read:
Level 2: 'COS(T^2+π/T)'
Level 1: 'T'

Press [RS] [COS] (∂) [EVAL]

Result: ((π - 2T^3)*sin((π + T^3)/T)/T^2

Alternatively:
Level 1: '∂T(COS(T^2+π/T))'
[RS] [COS] ( ∂ ) [EVAL]

INTVX: Symbolic indefinite integral of any expression where X is the independent variable (assumes you have X set up as the independent variable)

Keystrokes: [SYMB] [F3] (CALC) [F4] (INTVX)

Example: Find ∫ e^(-5x) dx.

By RPN: 5 [+/-] [ENTER] [big X] [ x ] [LS] [y^x] (e^x) [SYMB] [F3] (CALC) [F4] (INTVX)

By Algebraic Object: [ ' ] [LS] [y^x] (e^x) [+/-] 5 [ x ] [big X] [ENTER] [SYMB] [F3] (CALC) [F4] (INTVX)

Result: e^(-5x)/-5

: Integration using lower and upper limits. Use this when you want to execute definite integrals. You can use any variable of integration with ∫.

Stack Setup:
Level 4: lower limit
Level 3: upper limit
Level 2: integrand
Level 1: variable of integration

Keystrokes: [RS] [TAN] ( ∫ )

As an algebraic object: ' ∫(lower,upper,integrand,variable of integration) ' Use [EVAL] to evaluate.

Example: Find the definite integral of x^2 -2 from 0 to 2.

Get the stack to read:
4: 0
3: 2
2: 'X^2 - 2'
1: 'X'

Press [RS] [TAN] ( ∫ )

Result: -4/3

Alternatively:
1: ' ∫(0,2,X^2-2,X) '
[RS] [TAN] ( ∫ )

Sums and Roots

To alternate between Real and Complex Mode

Press and HOLD [LS], then press [TOOL]. A "R=" indicator states that you are operating in the Real mode. A "C=" indicator states that you are operating in the Complex mode.

You can also press [MODE] [F3] (CAS) and check (or uncheck) Complex and press [F6] (OK) twice.

The imaginary character has the sequence [LS] [TOOL] (i). You must put a multiplication sign between the imaginary part and i. Example: 5*i

ZEROS: Finds the roots of an expression in terms of any variable.

Stack Setup:
Level 2: 'expression (don't put an equals sign in it)'
Level 1: 'variable to solve for'

Here we are assuming that the expression equals 0.

Keystrokes: [SYMB] [F5] (SOLVE) [F6] (ZEROS)

Example: Find the roots of x^4 - 1.

Get the stack to read this:
Level 2: 'X^4-1'
Level 1: 'X'
Press [SYMB] [F5] (SOLVE) [F6] (ZEROS)

Result:
{-1, 1} in Real Mode
{i, -1, -i, 1} in Complex Mode

Possible set of keystrokes (by Algebraic Object): [ ' ] [big X] [y^x] 4 [ - ] 1 [ENTER] [ ' ] [big X] [ENTER] [SYMB] [F5] (SOLVE) [F6] (ZEROS)

SOLVEVX: Solves for X in any equation.

Keystrokes: [SYMB] [F5] (SOLVE) [F4] (1st SOLVE)

Example: Find the solution to 2√x + 3 = 5.

Possible set of keystrokes (by Algebraic Object): [ ' ] 2 [ x ] [ √ ] [big X] [ + ] 3 [RS] [+/-] (=) 5 [ENTER] [SYMB] [F5] (SOLVE) [F4] (1st SOLVE)

Result: 1

CAUTION: Not all equations can be solved this way.

SOLVE: Solves an equation for any variable.

Stack setup:
Level 2: equation
Level 1: 'variable'

Keystrokes: [SYMB] [F5] (SOLVE) [F5] (2nd SOLVE)

Try the above example using SOLVE.

: The Summation function. You can calculate finite sums and convergent infinite sums.

Stack Setup:
Level 1: variable (summation index, I recommend X)
Level 2: initial value
Level 3: final value
Level 4: summand, expression

Keystrokes: [RS] [SIN] ( ∑ )

To type infinity: [LS] 0 ( ∞ )

Alternatively: ' ∑(index=initial value,final value,expression) ' [EVAL] (or [RS] [ENTER] for a numerical approximation)

Example: Find the sum of the numbers from 1 to 25.

Get the stack to read this:
Level 1: 'X'
Level 2: 1
Level 3: 25
Level 4: 'X'
Press [RS] [SIN] ( ∑ )

Alternatively:
Level 1: ' ∑(X=1, 25, X)'
Press [RS] [SIN] ( ∑ )

Result: 325

This wraps up Part 6. We get back to programming in Part 7, where we invoke the solver. Thanks for reading, Eddie.


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

RPL Programming Tutorial - Part 5 - HP 49g+/50g: Prompt and Introduction to Algebraic Objects

Excuse me, but I must prompt you for something.

Welcome to the second week of my RPL tutorials, using the Hewlett Packard HP 49g+ and 50g calculators. Today's session will cover the PROMPT command.

The PROMPT command sets the program to ask the user for input. That input can be whatever you practically want: text, numbers, matrices, and equations. The user enters the requested information and presses the key sequence [LS] [ON] (CONT) . The [LS] [ON] sequence tells the calculator that the user is ready to move on.

The PROMPT structure is this:

"String that asks the user for input" PROMPT

Today we will do two programs using PROMPT: a simple program that picks an integer from 1 to N, and a more complex one that takes an equation and graphs it.

In this bag we have lotto balls from 1 to 49, and the first number is...

This program will ask you for a number (N), the number of draws (X), and the calculator will return X integers randomly selected from 1 to N. One caveat in this program is that the numbers selected can repeat.

The Program ONETO

Comments will be italicized, starting with an asterisk. You will not need to pre-load the stack with ONETO - all the inputs will be prompted for.

As a reminder:

[LS] means the left shift key (white on the 50g, green on the 49g+)
[RS] means the right shift key (orange on the 50g, red on the 49g+)
Pressing [ALPHA] twice will put the calculator in ALPHA-LOCK mode. If you want lower case letters, press [LS] then the letter. For greek and other characters, select [RS] then the letter.

Hint:

During program entry, you can press [RS] [ . ] for a carriage return. This can make program entry easier to see and read. Best of all, this does not affect program entry or execution.

Note:

The key [big X] is located on the 5th rows of keys up from the bottom. I will use this to distinguish the X character from the times key [ x ].

Program Input:

[RS] [ + ] ( << >> )
* Start the program entry
[RS] [ x ] ( "" )
[ALPHA] [ALPHA] [MODE] (H) [TOOL] (I) [APPS] (G) [MODE] (H) [SPC] [EVAL] (N) [TAN] (U) [HIST] (M) [F2] (B) [F5] (E) [ √ ] (R) [RS] [+/-] (=) [ALPHA]
[ &rarr ] [LS] [EVAL] (PRG) [NXT] [F5] (IN) [NXT] [F1] (PROMPT)

* Enters the first prompt request, "HIGH NUMBER="
[RS] [ x ] ( "" )
[ALPHA] [ALPHA] [LS] 3 (#) [SPC] [ ' ] (O) [F6] (F) [SPC] [F4] (D) [ √ ] (R) [F1] (A) [+/-] (W) [SIN] (S) [RS] [+/-] (=) [ALPHA]
[ &rarr ] [F1] (PROMPT)

* Enters the second prompt request, "# OF TIMES="
[RS] 0 ( &rarr ) [ALPHA] [EVAL] (N) [SPC] [big X]
* Enters N and X and declares them as local variables
[RS] [ + ] (<< >>) 1 [SPC] [big X]
[F6] (PRG) [F3] (BRCH) [LS] [F4] (FOR)

* Use the current menu to go back to the Program level, enters FOR-NEXT structure
[ALPHA] [STO>] (K) [SPC] [ALPHA] [EVAL] (N)
[LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F4] (RAND)
[ x ] 1 [ + ] [NXT] [F6] (MTH) [F5] (REAL) [NXT] [IP] (F5)

* Enters the commands for the For loop
[ENTER]
* Terminate program entry

[ ' ] [ALPHA] [ALPHA] [ ' ] (O) [EVAL] (N) [F5] (E) [COS] (T) [ ' ] (O) [ALPHA] [ENTER] [STO>]

The completed program:

<< "HIGH NUMBER=" PROMPT
"# OF DRAWS=" PROMPT
&rarr N X
<< 1 X
FOR K N RAND * 1 + IP
NEXT >> >>


Instructions:

1. Run ONETO
2. The calculator will prompt "HIGH NUMBER=" at the top of the screen. Enter the high number and then press [LS] [ON] (CONT).
3. The calculator will prompt "# OF DRAWS=" at the top of the screen. Enter the number of draws and then press [LS] [ON] (CONT).
4. The calculator fills the stack with randomly selected numbers. Use [HIST] and [ &uarr ] to view the numbers. Press [ON] when done viewing the stack.
5. You may want to clear the stack before continuing.

Example:

A possible set of 12 random integers from 1-12 is: 9, 4, 7, 2, 11, 1, 10, 4, 1, 4, 1, 7.

Graphing an equation from the Stack Program

This program graphs a given an function y(x) using specified window settings. This is just one way of graphing an equation, which is an alternate way to graphing functions without using the graphing set up screens (Y=, WIN, GRAPH, and 2D/3D). The function can be traced and analyzed just like any other functions that are plotted.

The Catalog

You can access all the commands that the 49g+ and 50g has in the catalog. To access the catalog, press [RS] [SYMB] (CAT). If you press [ALPHA] and a letter, you can quickly scroll to that part of the catalog. You may be able to get a few letters if you are fast enough.

The other thing that is nice about the 49g+ and 50g is that the commands can be typed. This may be a helpful and faster alternate than trying to hunt commands in the menu or catalog. However, in this tutorial, the keystrokes I show will make use of the catalog.

Commands that are Used

* XRNG: Sets the left and right boundaries of the plot screen. The left boundary is taken from Level 2; the right boundary is taken from Level 1.
* YRNG: Sets the bottom and top boundaries of the plot screen. The bottom boundary is taken from Level 2; the top boundary is taken from Level 1.
* FUNCTION: Sets the calculator to Function mode.
* STEQ (Store Equation): Stores an equation in the EQ variable. The EQ variable is a system variable which the calculator uses to plot and solve equations with. EQ can have a list of more than one equation or expression.
* INDEP: Sets a variable as independent. Useful when setting up a plot. It makes sense to make the independent variable 'X' or even 'T' or ' θ', but you can make the independent variable anything you want.
* ERASE: Erases the plot screen and gets the calculator ready to draw a fresh, new plot.
* DRAW: Has the calculator draws whatever is stored in EQ.
* DRAX (Draw the Axes): Has the calculator draw the axes.
* PICTURE: Switches the calculator to the plot (picture) environment.

With all these commands to play with, let's program GRPFX.

The Program GRPFX

[RS] [ + ] (<< >>)
[RS] [ x ] ( "" )
[ALPHA] [ALPHA] [1/x] (Y) [LS] [ - ] (parenthesis) [big X] [RS] [+/-] (=)

* Input the string "Y="
[LS] [EVAL] (PRG) [NXT] [F5] (IN) [NXT] [F1] (PROMPT)
* Inserts the Prompt command. Leave this menu open.
[RS] [SYMB] (CAT) [ALPHA] [SIN] (S) scroll until you find STEQ
[F6] (OK)

* Use the catalog to find the STEQ command. You can hold [ &darr ] and [ &uarr ] to quickly scroll the catalog.
[RS] [SYMB] (CAT) [ALPHA] [F6] (F) find FUNCTION [F6] (OK)
* Set the calculator to FUNCTION mode
[ ' ] [ (big) X ] [ &rarr ] [RS] [SYMB] [ALPHA] [TOOL] (I) find INDEP [F6] (OK)
* Set X to be the independent variable.
[RS] [ x ] ( "") [ALPHA] [ALPHA] [big X] [HIST] (M) [TOOL] (I) [EVAL] (N) [RS] [+/-] (=) [F1] (PROMPT)
[RS] [ x ] ( "" ) [ALPHA] [ALPHA] [big X] [HIST] (M) [F1] (A) [big X] [RS] [+/-] (=) [F1] (PROMPT)
[RS] [SYMB] (CAT) [big X] find XRNG [F6] (OK)

* Prompt for the left and right boundaries, then use the XRNG command.
[RS] [ x ] ( "" ) [ALPHA] [ALPHA] [1/X] (Y) [HIST] (M) [TOOL] (I) [EVAL] (N) [RS] [+/-] (=) [F1] (PROMPT)
[RS] [ x ] ( "" ) [ALPHA] [ALPHA] [1/X] (Y) [HIST] (M) [F1] (A) [big X] [RS] [+/-] (=) [F1] (PROMPT)
[RS] [SYMB] (CAT) [ALPHA] [1/X] (Y) find YRNG [F6] (OK)

* Prompt for the bottom and top boundaries, then use the YRNG command.
[RS] [SYMB] (CAT) [ALPHA] [F5] (E) find ERASE [F6] (OK)
[RS] [SYMB] (CAT) [ALPHA] [F4] (D) find DRAX [F6] (OK)
[RS] [SYMB] (CAT) [ALPHA] [F4] (D) find DRAW [F6] (OK)

* Input the ERASE, DRAX, and DRAW commands.
[RS] [SYMB] (CAT) [ALPHA] [SYMB] (P) find PICTURE [F6] (OK) [ENTER]
* Input the PICTURE command and terminate program entry.

The completed program:

<< "Y(X)=" PROMPT
STEQ
FUNCTION
'X' INDEP
"XMIN=" PROMPT "XMAX=" PROMPT XRNG
"YMIN=" PROMPT "YMAX=" PROMPT YRNG
ERASE DRAX DRAW
PICTURE >>



Algebraic Objects

Simply put, algebraic objects are equations or formulas that are enclosed in single quotes. Examples include:

'1'
'X+2/5'
'SIN(π-1/2)'
'e^5.2-SQ(3)'

Algebraic objects gives the user an alternative (and maybe easier) way for the user to enter equations. In Part 6, we will explore several common functions that can be used with algebraic objects.

We can also enter equations using the RPN method. Let's try an example:

To enter 'X^2 + 3X - 1', we can enter this two ways. Assume X does not have anything stored in it. Purge X if need be.

RPN Way: [big X] [ENTER]
* duplicates X.
[LS] [ √ ] (x^2) [LS] [ &rarr ] (SWAP) 3 [ x ] [ + ] 1 [ - ] [EVAL]

Use [EVAL] to simplify the expression.

Algebraic Object: [ ' ] [big X] [y^x] 2 [ + ] 3 [ x ] [big X] [ - ] 1 [ENTER]

Instructions for GRPFX:

1. Run GRPFX. All the input will be asked for you, so you don't need anything in the stack to start with.
2. At the "Y(X)=" prompt, enter a function in X. You can use RPN, an algebraic object, or use the equation writer. Please be aware that the prompt may disappear when you are entering the function, just continue. Press [LS] [ON] (CONT) to continue.
3. At the "XMIN=" prompt, enter the left boundary, then press [LS] [ON] (CONT).
4. At the "XMAX=" prompt, enter the right boundary, then press [LS] [ON] (CONT).
5. At the "YMIN=" prompt, enter the bottom boundary, then press [LS] [ON] (CONT).
6. At the "YMAX=" prompt, enter the top boundary, then press [LS] [ON] (CONT).
7. You will see the function plotted. Use [F3] [F2] to trace the function. [F4] will give you access to function analysis such as ROOT, SLOPE, and AREA. Press [ON] to get back to the home screen.

The following pictures show GRPHX in action while plotting y(x) = x^2 + 3x - 1. Using the window, X = [-10, 10] and Y = [-10, 10]. (I am took pictures at a coffee shop using the iPad)

Hope you enjoyed Part 5. Come back for Part 6 where we explore cool functions with algebraic objects.

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

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...