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] ( ∑ )

1 comment:

  1. Dear Eddie,
    Many thanks for this very useful 17 part tutorial!
    Btw have you ever found a way to comment code out with the HP50g? (Similar to the % in Matlab? I know about using @, but the code following this will get deleted upon pressing enter. If there was a workaround this would be really handy!

    ReplyDelete

How to Rotate Graphs

How to Rotate Graphs Introduction The key is to use parametric equations in our rotation.  Using the rotation angle θ, the rotatio...