Showing posts with label Hewlett. Show all posts
Showing posts with label Hewlett. Show all posts

Monday, October 24, 2011

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 - 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 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.

Thursday, October 6, 2011

RPL Programming Tutorial - Part 3 - HP 49g+/50g: If-Then-Else

If Only...

Welcome to Part 3 of the RPL Programming Tutorial with the HP 49g+ and HP 50g calculator. To recap, Part 1 discussed the basics of RPL programming and Part 2 introduced the concept of local variables.

In Part 3 we will dive into the IF-THEN and IF-THEN-ELSE structures. These structures test data against a condition, and then instructs the machine to execute designated program code based on the results.

In general, an IF-THEN-ELSE-END structure looks like this:

IF condition listed here (i.e. x = 5, y > 10, z ≤ 0, a ≠ b, etc.)
THEN commands to be done if the condition is true
ELSE commands to be done if the condition is false
END

How to find the IF menu

You can input the IF, THEN, ELSE, and END program commands separately. However, the HP 50g (and 49g+) gives the user another choice. With a keystroke sequence, you can enter the entire sequence as a template.

To insert the templates:

Start by pressing [LS] [EVAL] (PRG) [F3] (BRCH) .

To insert an IF-THEN-END structure, press [LS] [F1] (IF).

To insert an IF-THEN-ELSE-END structure, press [RS] [F1] (IF).

The next two programs will show an example of each of the two structures.

The Online Shipping Deal

A famous online store is running a promotion: Order at least $100.00 from our store, and we'll pay the $5.95 shipping fee! This program calculates the total amount of the order, with shipping if any. Assume the store charges 7.5% sales tax on all orders including shipping.

Notes:
1. The local variable A will be used to designate the amount of goods purchased.
2. Since A + y% = A + x * y /100 = A * (1 + y /100), we will multiply the amount plus shipping by 1.075. (Let y = 7.5%)
3. The $5.95 shipping charge applies only when the order amount is less than $100.00. Set up the test this way: If A < 100, add 5.95 to A, otherwise do nothing. Because we are only executing further instructions only when the condition is true, no ELSE command is necessary.

The Program ONSALE

Comments will be italicized, starting with an asterisk. This program assumes that the purchase amount is on Level 1 of the stack.

[RS] [ + ] (<< >>)
* Start of the program
[RS] [ 0 ] (&rarr)
[ALPHA] [F1] (A)

* Assign the amount to the local variable A
[RS] [ + ] (<< >>)
* Start the main program
[ALPHA] [F1] (A)
* Call A to the stack
[LS] [EVAL] (PRG)
[F3] (BRCH)
[LS] [F1] (IF)

* Insert the IF-THEN-END structure
[ALPHA] [F1] (A)
[SPC] 100 [RS] [ X ] (<)

* Insert the test condition A < 100
[ &darr ] (down arrow)
5.95 [ + ]

* Add shipping charge if A < 100
[ &darr ] 1.075 [ x ] [RS] [ENTER] (&rarr NUM) [ENTER]
* Finish the program

[ ' ] [ALPHA] [ALPHA] [ ' ] (O) [EVAL] (N) [SIN] (S) [F1] (A) [NXT] (L) [F5] (E) [ENTER] [STO>]

The completed program ONSALE:
<< &rarr A << A IF A 100 < THEN 5.95 + END 1.075 * &rarr NUM >> >>

Instructions:
1. Enter the amount on Level 1 of the stack.
2. Run ONSALE.

Test Data:

Input = 50, Result = 60.14625 (A $50.00 order results in a total bill of $60.15.)

Input = 99.99, Result = 113.8855 (A $99.99 order results in a total bill of $113.89)

Input = 100, Result = 107.5 (A $100.00 order results in a total bill of $107.50. Surprised? Remember all orders $100.00 or more result in the shipping charged being waived.)

Input = 149.99, Result = 161.23925 ($149.99 order yields a bill of $161.24)

f(x) = (sin x)/x

This program calculates the function f(x) = (sin x)/x for all real numbers. If we attempt to calculate f(0) directly, we would get a "division by zero" error. However, the calculus limit as f(x) approaches 0 is 1. Let's create a test condition that detects for an input of 0. If the input is anything else, f(x) computes normally.

Note: The test of equality requires two equal signs, ==. This can be typed directly from the keyboard via alpha or by the TEST submenu of the PROGRAM menu. This program uses TEST submenu method (4 keystrokes opposed to 6 keystrokes).

The Program SINX

The program takes X from Level 1 of the stack and stores it as the local variable X.

[RS] [ + ] (<< >>)
[RS] [ 0 ] (&rarr)
[ X ]

* Stores the contents of Level 1 in the local variable X
[RS] [ + ] (<< >>)
[LS] [EVAL] (PRG)
[F3] (BRCH)
[RS] [F1] (IF)

* Inserts the IF-THEN-ELSE-END structure
[ X ] [SPC] 0
[LS] [EVAL] (PRG) [F4] (TEST) [F1] (==)

* Inserts the double equals sign, ==, for the equality test. Test X = 0?
[ &darr ] [SPC] 1
* Enters the commands should X = 0 (THEN)
[ &darr ] [SPC]
[ X ] [SIN] [ X ] [ ÷ ]
[RS] [ENTER] (&rarr NUM)

* Enters the commands should X ≠ 0 (ELSE)
[ENTER]
* Terminates program entry

[ ' ] [ALPHA] [ALPHA] [SIN] (S) [TOOL] (I) [EVAL] (N) [ X ] (X) [ENTER] [STO>]

The complete program:
<< &rarr X << IF X 0 == THEN 1 ELSE X SIN X / &rarr NUM END >> >>

Source: HP 48SX Scientific Expandable Calculator: Owner's Manual Volume II. Hewlett Packard, 3rd Edition, 1990

Instructions for SINX:
1. Enter X on the stack.
2. Run SINX.

Test Data - Assume the calculator is in Radians mode:

Input = -1, Result = 0.841470984808

Input = 0, Result = 1 (If you get this, then the IF-THEN-ELSE-END structure worked)

Input = 1, Result = 0.841470984808

Coming up, we'll take a look at the FOR-NEXT structure. See you next time in Part 4!

Eddie


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

RPL Programming Tutorial - Part 2 - HP 49g+/50g: Local Variables

Welcome!

Welcome to Part 2 of the RPL Programming Tutorial for the HP 49g+ and 50g calculators. To recap, Part 1 talked about how to create, save, run, and (if need be) delete a program.

In Part 2, introduces the concept of the local variable. Simply put, a local variable is a variable that is used in a program and is then purged (deleted) at the end of the program. Local variables are not stored outside of the program, which saves memory.

A general structure of declaring local variables goes like this:

<< commands needed to set up the local variables, if any &rarr Local Variables
<< main program >> >>

=================================================================
Hint: There are times that you want to store information outside of a program. To do so, just store the data in a variable enclosed in single quotes followed by a STO command. These variables are called global variables.
=================================================================

Fibonacci Sequence

The well known Fibonacci Sequence is:
1, 1, 2, 3, 5, 8, 13, 21, 34,...

After the first two numbers, each succeed number is the sum of the last two numbers.

F_n = F_(n-1) + F_(n-2) where F_1 = 1 and F_2=1.

You can quickly find the mth term of the Fibonacci Sequence by using this closed formula:

f(n) = (ø^(n + 2) - (1 - ø)^(n + 2)) ÷ √5

Where:
ø = (1 + √5) ÷ 2, the Golden Ratio
n = m - 2

There are two local variables used in this program:
N = M - 2, the user supplies where M is the desired mth term
H = ø

The Program FIBN

Comments will be italicized, starting with an asterisk *. This program starts with M on Level 1 of the stack.

[RS] [ + ] (<< >>)
* Start of the program
2 [ - ]
* Subtract 2 from M to get N
1 [SPC] 5 [ √ ] [ + ]
2 [ ÷ ]

* Set up the Golden Ratio Constant, to be stored in H
[RS] [ 0 ] (&rarr)
* Prepare to name the local variables
[ALPHA] [EVAL] (N) [SPC]
[ALPHA] [MODE] (H)
[RS] [ + ] (<< >>)

* Start the main program
[ALPHA] [MODE] (H) [SPC]
* Leave spaces in between H and N
[ALPHA] [EVAL] (N) [SPC]
2 [ + ] [y^x]

* H^(N + 2); [y^x] is shown as ^
1 [SPC] [ALPHA] [MODE] (H) [ - ]
[ALPHA] [EVAL] (N) [SPC] 2
[ + ] [y^x]

* (1 - H)^(N + 2)
[ - ]
* H^(N + 2) - (1 - H)^(N + 2)
5 [ √ ] [ ÷ ]
* ( H^(N + 2) - (1 - H)^(N + 2) ) ÷ √5
[EVAL]
* To simplify the answer
[ENTER]
* To terminate program entry

[ ' ] [ALPHA] [ALPHA]
[F6] (F) [TOOL] (I) [F2] (B) [EVAL] (N)
[ENTER] [STO>]


Here is the completed program:

<< 2 - 1 5 √ + 2 / → N H
<< H N 2 + ^ 1 H - N 2 + ^ - 5 √ / EVAL >> >>


How to run FIBN:
1. Enter M on the Stack
2. Run FIBN

Results:
FIBN(1) = 1
FIBN(2) = 1
FIBN(3) = 2
FIBN(4) = 3
FIBN(5) = 5
etc...

That wraps up Part 2. In Part 3, the IF-THEN-END and IF-THEN-ELSE-END program structures are introduced. Until then, Cheers! Eddie

Source Used: Math Formulas and Tables from Mobile Reference. SoundTells, LLC 2003-2010

This tutorial is created and is the property of Edward Shore. No mass reproduction without express permission of the author.


Edit: 10/20/11: correct an error in the formula in the text. The program is correct.

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


RPL Tutorial - Part 1

Introduction

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

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

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

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

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

Getting Started

Shift and Soft Keys

For the HP 50g:

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

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

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

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

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

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

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

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

Setting the 50g to RPN Mode

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

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

Your calculator is set. (49g+ users follow the same instructions)

Setting Soft Menus

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

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

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

Brackets

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

How to Name Programs

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

Note that:

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

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

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

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

How to Name a Program:

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

How to delete a Program:

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

Your First Program

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

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

Commands Used

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

The Program ACIR

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

Ready?

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

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


Store the program in variable ACIR

The Program:

<< SQ π * ->NUM >>

Running ACIR

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

An alternative way:

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

Results:

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

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

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

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

Friday, September 30, 2011

Common Keyboard Commands for Hewlett Packard RPL Calculators (HP 48S/48G/50g)


(updated 10/1/2011)

This is a quick reference to common mathematical functions for the Hewlett Packard RPL calculators. In general, HP RPL calculators are classified into three families:

This table will focus on the HP 48S, 48G, and 50g - three of four models I actually own (I have a 49g+ which should be the same key mapping as the 50g. The 49G has a different mapping - and I do not own a 49G.)

Note: [LS] = left shift key (3rd key up from the ON button on the left side)
[RS] = right shift key (2nd key up from the ON button on the right side)

About Soft Keys

On the top row, there are six soft keys. The functions of these six keys change depending on what menu is currently active. The top row of the HP 49G, 49g+, and 50g are labeled as:

[F1] [F2] [F3] [F4] [F5] [F6]

On the HP 48S and 48G, these keys are not labeled - but I will still use the F# convention. So [F1] means first soft key from the left, [F2] means second soft key from the left, and so on.

Note: For the 50g, it is assumed that Soft Menus are turned on. (Flag -117 is set)

List of Functions

x^2
HP 48S/48G: [LS] [ √x ]
HP 50g: [LS] [ √X ]

x√y
HP 48S/48G: [RS] [√x]
HP 50g [RS] [√X]

10^x
HP 48S/48G: [LS] [y^x]
HP 50g: [LS] [EEX]

LOG
HP 48S/48G: [RS] [y^x]
HP 50g: [RS] [EEX]

e^x
HP 48S/48G: [LS] [1/x]
HP 50g: [LS] [Y^X]

LN
HP 48S/48G: [RS] [1/x]
HP 50g: [RS] [Y^X]

ABS
HP 48S: [MTH] [ F1 ] (PARTS) [ F1 ] (ABS)
HP 48G: [MTH] [F5] (REAL) [NXT] [F1] (ABS)
HP 50g: [LS] [ ÷ ]

ARG
HP 48S: [MTH] [ F1 ] (PARTS) [ F4 ] (ARG)
HP 48G: [MTH] [NXT] [F3] (CMPL) [F6] (ARG)
HP 50g: [RS] [ ÷ ]

ASIN
HP 48S/48G: [LS] [SIN]
HP 50g: [LS] [SIN]

ACOS
HP 48S/48G: [LS] [COS]
HP 50g: [LS] [COS]

ATAN
HP 48S/48G: [LS] [TAN]
HP 50g: [LS] [TAN]

->NUM
HP 48S: [RS] [EVAL]
HP 48G: [LS] [EVAL]
HP 50g: [RS] [ENTER]

->Q (Exact Answer)
HP 48S: [LS] [EVAL]
HP 48G: [LS] [ 9 ] (SYMBOLIC) [NXT] [F3]
HP 50g: [LS] [ 6 ] (CONVERT) [F4] (REWRI) [NXT] [F5] (->Q)

x!
HP 48S: [MTH] [F2] (PROB) [F3] (!)
HP 48G: [MTH] [NXT] [F1] (PROB) [F3] (!)
HP 50g: [LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F3] (!)

COMB (Combination)
HP 48S: [MTH] [F2] (PROB) [F1] (COMB)
HP 48G: [MTH] [NXT] [F1] (PROB) [F1] (COMB)
HP 50g: [LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F1] (COMB)

PERM (Permutation)
HP 48S: [MTH] [F2] (PROB) [F2] (PERM)
HP 48G: [MTH] [NXT] [F1] (PROB) [F2] (PERM)
HP 50g: [LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F2] (PERM)

RAND (Random #)
HP 48S: [MTH] [F2] (PROB) [F4] (RAND)
HP 48G: [MTH] [NXT] [F1] (PROB) [F4] (RAND)
HP 50g: [LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F4] (RAND)

% (Returns level 2 * level 1% on level 1)
HP 48S: [MTH] [F1] (PARTS) [NXT] [F4] (%)
HP 48G: [MTH] [F5] (REAL) [F1] (%)
HP 50g: [LS] [SYMB] (MTH) [F5] (REAL) [F1] (%)

%CHG (Percent Change from level 2 to level 1)
HP 48S: [MTH] [F1] (PARTS) [NXT] [F5] (%CH)
HP 48G: [MTH] [F5] (REAL) [F2] (%CH)
HP 50g: [LS] [SYMB] (MTH) [F5] (REAL) [F2] (%CH)

IP (Integer Part)
HP 48S: [MTH] [F1] (PARTS) [NXT] [NXT] [F3] (IP)
HP 48G: [MTH] [F5] (REAL) [NXT] [F5] (IP)
HP 50g: [LS] [SYMB] (MTH) [F5] (REAL) [NXT] [F5] (IP)

FP (Fraction Part)
HP 48S: [MTH] [F1] (PARTS) [NXT] [NXT] [F4] (FP)
HP 48G: [MTH] [F5] (REAL) [NXT] [F6] (FP)
HP 50g: [LS] [SYMB] (MTH) [F5] (REAL) [NXT] [F6] (FP)

To access the hyperbolic functions (SINH, COSH, etc..)
HP 48S: [MTH] [F3] (HYP)
HP 48G: [MTH] [F4] (HYP)
HP 50g: [LS] [SYMB] (MTH) [F4] (HYP)

Matrix Functions:

INV (Inverse)
HP 48S/48G: [1/x]
HP 50g: [1/X]

DET (Determinant)
HP 48S: [MTH] [F4] (MATR) [F5] (DET)
HP 48G: [MTH] [F2] (MATR) [F2] (NORM) [NXT] [F2] (DET)
HP 50g: [LS] [ 5 ] (MATRICES) [F2] (OPER) [F6] (DET)

M^T (Transpose)
HP 48S: [MTH] [F4] (MATR) [F3] (TRN)
HP 48G: [MTH] [F2] (MATR) [F1] (MAKE) [F3] (TRN)
HP 50g: [LS] [ 5 ] (MATRICES) [F2] (OPER) [NXT] [NXT] [F5] (TRN)

EGVL (Eigenvalues)
(not on the HP 48S)
HP 48G: [MTH] [F2] (MATR) [NXT] [F3] (EGVL)
HP 50g: [LS] [ 5 ] (MATRICES) [NXT] [F1] (EIGEN) [F3] (EGVL)

RREF
(not on the HP 48S)
HP 48G: [MTH] [F2] (MATR) [F3] (FACTR) [F1] (RREF)
HP 50g: [LS] [ 5 ] (MATRICES) [F5] (LIN S) [F4] (RREF)

Stack Functions:

Clear the Entire Stack
HP 48S: [RS] [backspace]
HP 48G: [LS] [DEL]
HP 50g: [RS] [Backspace]

Swap contents of levels 1 and 2
HP 48S: [LS] [right arrow] (SWAP)
HP 48G: [LS] [right arrow] (SWAP)
HP 50g: [LS] [right arrow] (unmarked)

Roll the entire stack down 1 level
(Move everything down one level and level 1 goes to stack n)
HP 48S: [PRG] [F1] (STK) [F6] (DEPTH) [F4] (ROLLD)
HP 48G: [LS] [up arrow] (STACK) [F6] (DEPTH) [F4] (ROLLD)
HP 50g: [LS] [EVAL] (PRG) [F1] [NXT] [F6] (DEPTH) [F2] (ROLLD)

Angle Conversions:

Degrees to Radians
HP 48S: [LS] [SPC] (π) [ x ] 180 [ ÷ ]
HP 48G: [MTH] [F5] (REAL) [NXT] [NXT] [F5] (D->R)
HP 50g: [LS] [SYMB] (MTH) [F5] (REAL] [NXT] [NXT] [F5] (D->R)

Radians to Degrees
HP 48S: 180 [ x ] [LS] [SPC] (π) [ ÷ ]
HP 48G: [MTH] [F5] (REAL) [NXT] [NXT] [F6] (R->D)
HP 50g: [LS] [SYMB] (MTH) [F5] (REAL] [NXT] [NXT] [F5] (R->D)

RPL Basics


RPL Basics
(updated 10/1/2011)





I dedicate this blog to Peter Murphy - thank you for the request!


This is a basic tutorial of reverse polish lisp (RPL). It is a combination of RPN (reverse polish notation), Lips, and Forth languages.


RPL removes the need to enter parenthesis during long calculations and allows for immediate feedback during calculations; you will not need to enter a long operation before getting feedback - thus eliminating errors. A lot of times, the number of keystrokes required to make a calculation is reduced using RPL compared to algebraic systems. RPL works like RPN, but there several differences.


All of the following calculators, manufactured by Hewlett Packard, operate on RPL: HP-28C, HP-48S, HP-48SX, HP-48G, HP-48G+, HP-48GX, HP-49G, HP 49g, HP 50g. Currently, only HP 50g is sold new. The rest can be found used (sometimes new) on other online vendors. There are also several emulators of RPL calculators (HP48+ for example) that can be used for the iPhone/iPod Touch/iPad and devices operating on Android.


There are two types of RPL: User and System. User RPL is for basic, everyday use. You can create programs with User RPL right on the calculator's keyboard. System RPL allows users to create faster and more efficient programs. However, System RPL programming is more difficult than User RPL - most of the time programs have to complied and then downloaded to the calculator. For our purposes of the tutorial, we will use User RPL ("Just use the keyboard"). You can find additional information on RPL on the HP Museum of Calculators' RPL Page.

The Stack

Typically, an RPL calculator uses a stack with an infinite amount of "levels" (or registers). Each level is stacked on top of another. The size of the stack is dynamic depending on the contents each level has. In my experience, I end up using 1 to 3 levels, but I can use as many levels as I want so long as I have memory. For example a four-level stack diagram looks like this:

4:
-------------------------------
3:
-------------------------------
2:
-------------------------------
1:
-------------------------------

The 28C displays 3 levels, the HP 48S and 48G series display 4 levels, and the HP 49G series, including the 49g+ and 50g can display any number depending on the screen's font setting. Typically, FONT 8 shows 7 levels.

What is required of the user to execute a desired operation depends on the number of arguments (for our purpose, numbers) the function requires. Most calculator functions require one or two arguments.


One-argument functions operate on whatever is in level 1, sometimes referred to as X register. For one-argument functions, simply execute the desired operation. One-argument functions include all the trigonometric functions (sine, cosine, tangent), logarithms, exponential (e^), reciprocal, square root, and factorial (x!). The change sign operation fits under the category of one-number operations because it simply multiplies the number by -1. The change sign operation is labeled [ +/- ].


Two-argument functions operate on the contents of levels 2 and 1. Level 2 is like the Y register and level 1 the X register. Common two-argument functions include the arithmetic operators (+, -, x, ÷), powers (y^x), combination and permutations, percent and percent change (Δ%). To use a two-argument function, enter the first number (y), then press ENTER. ENTER terminates the entry and gets the calculator ready to receive another number. Next, enter the second number (x). A second ENTER is not required because executing the operation terminates the second entry. In summary, to operate a two-argument function:


1. Enter the first (y) argument,

2. Press ENTER to terminate the first entry.

3. Enter the second (x) argument,

4. Execute the desired function.


When you link more than one operation, it is known as a chain calculation. A simple example is adding a list four numbers. Another example is adding two groups of numbers and then multiplying the two sums together.


In chain calculations, whatever in the display becomes the first argument of the operation. All that is needed is to enter the second argument (number), and then the required function. For chain calculations:


1. Enter the next required argument

2. Execute the desired function, no ENTER is required


The scope of this blog is just to give a very basic tutorial of RPL. It is a "do by example" tutorial. Keystrokes are shown in blue. All calculations on this blog are rounded to 4 decimal places.

This blog will demonstrate keystrokes on the 48S (works also on the 48SX), 48G (works also on the 48G+ and 48GX), and the 50g (works also on the 49g+).

==========================================================

To set the calculator to 4 decimal places:

HP 48S:

4 [ENTER] [LS] [CST] (MODES) [2nd soft key from left] (FIX)

HP 48G (via the Mode Selection Screen):

[LS] [MODES], choose Fix 4 on the menu

HP 50g (via the Mode Selection Screen):

[MODE], choose Fix 4 on the menu.

=========================================================

Examples: Calculating with RPL

Format of the display will be shown as follows:
[...]
[2: contents]
[1: contents]

Shift Keys

Left Shift [LS]: This key has an arrow going up and turning left. It is the third key up from the ON button on the left side. It is orange on the 48S, purple on the 48G, periwinkle on the 49G, green on the 49g+, and white on the 50g.

Right Shift [RS]: This key has an arrow going up and turning right. It is the second key up from the ON button on the right side. It is blue on the 48S, green on the 49G, light red on the 49G, red on the 49g+, and orange on the 50g.

The 28C has 1 shift key - in red.

Soft Keys: There are six soft keys on the top row of the keyboard. Their functions change depending on the current active menu. On the 48S and 48G series, these keys are not labeled. On the 49G, 49g+, and 50g, they are labeled F1 through F6, left to right. The soft keys are labeled as:

[F1] [F2] [F3] [F4] [F5] [F6]

In this tutorial I will put the label on the soft keys. [F1] mean the leftmost soft key, [F2] is the second leftmost key, and so on. Got it?

In this tutorial I will put the label of any shifted function or any function accessed by a soft key parenthesis after the key. For example, for the square function:

[LS] [ √ ] (x^2)

Press the left shift key, then the square root key. The square function is just labeled as the left-shifted function of that key.

Note: For the 50g, it is assumed that Soft Menus are turned on. (Flag -117 is set)

#1: 5 + 8

Keystrokes:

HP 48S/48G/50g: [ 5 ] [ENTER]

Display: [1: 5.0000]

HP 48S/48G/50g: [ 8 ] [ + ]

Display: [1: 13.0000]

Result: 13

#2: Chain Addition: 1000 + 1500+ 1750

Keystrokes:

HP 48S/48G/50g: 1000 [ENTER]

Display: [1: 1000.0000]

HP 48S/48G/50g: 1500 [ + ]

Display: [1: 2500.0000]

HP 48S/48G/50g: 1750 [ + ]

Display: [1: 4250.0000]

Result: 4,250

#3: To Clear the Stack

HP 48S: [LS] [backspace key]
HP 48G: [LS] [DEL]
HP 50g: [LS] [backspace key]

#4: 10 - 6

As in any calculation involving subtraction or division, the order of the arguments is important.

Keystrokes:

HP 48S/48G/50g: 10 [ENTER]

Display: [1: 10.0000]

HP 48S/48G/50g: 6 [ - ]

Display: [1: 4.0000]

Result: 4

#5: 6 x 2.95 + 2 x 1.28

Sometimes it is useful to leave previous results on the stack while working on parts of the problem. The order of operations tells us to do multiplication first, then addition.

HP 48S/48G/50g: 6 [ENTER] 2.95 [ x ]

Display:
[1: 17.7000]

Leave 17.7 on the stack for future use.

HP 48S/48G/50g: 2 [ENTER]

Display:
[2: 17.7000]
[1: 2.0000]

HP 48S/48G/50g: 1.28 [ x ]

Display:
[2: 17.7000]
[1: 2.5600]

Now complete the calculation.

HP 48S/48G/50g: [ + ]

Display:
[1: 20.2600]

Result: 20.26

# 6: 200 ÷ (3^2.5 - 1)

Keystrokes:

We'll start by entering 200 and leaving it on the stack for future use.

HP 48S/48G/50g: 200 [ENTER] 3 [ENTER]

Display:
[2: 200.0000]
[1: 3.0000]

HP 48S/48G/50g: 2.5 [y^x]

Display:
[2: 200.0000]
[1: 15.5885]

HP 48S/48G/50g: 1 [ - ]

Display:
[2: 200.0000]
[1: 14.5885]

We are ready for the division.

HP 48S/48G/50g: [ ÷ ]

Display:
[1: 13.7095]

Result: 13.7095

#7: 2 x (5 ^ 2.5 ÷ 2.5 ^ 5)

Take care of the fraction first, multiply it all by 2 in the end.

HP 48S/48G/50g: 2 [ENTER] 5 [ENTER]

Display:
[2: 2.0000]
[1: 5.0000]

HP 48S/48G/50g: 2.5 [y^x]

Display:
[2: 2.0000]
[1: 55.9017]

HP 48S/48G/50g: 2.5 [ENTER] 5 [y^x]

Display:
[3: 2.0000]
[2: 55.9017]
[1: 97.6563]

HP 48S/48G/50g: [ ÷ ]

Display:
[2: 2.0000]
[1: 0.5724]

Finish it off.

HP 48S/48G/50g: [ x ]

Display:
[1: 1.1449]

Result: 1.1449

# 8: 1/2 + 3/7 - √(25/64)

√ is the symbol for square root

Keystrokes (or one possible set of keystrokes):

HP 48S/48G/50g: 2 [1/x]

Display:
[1: 0.5000]

HP 48S/48G/50g: 3 [ENTER] 7 [ ÷ ]

Display:
[2: 0.5000]
[1: 0.4286]

HP 48S/48G/50g: [ + ] 25 [ENTER] 64 [ ÷ ]

Display:
[2: 0.9286]
[1: 0.3906]

HP 48S/48G/50g: [ √ ]

Display:
[2: 0.9286]
[1: 0.6250]

HP 48S/48G/50g: [ - ]

Display:
[1: 0.3036]

Result: 0.3036

#9: Find a decimal approximation, to four decimal places, of e^-3.

Keystrokes:

HP 48S: [ 3 ] [+/-] [LS] [1/x] (e^x)
HP 48G: [ 3 ] [+/-] [LS] [1/x] (e^x)
HP 50g: [ 3] [+/-] [LS] [y^x] (e^x) [RS] [ENTER] (->NUM)

Result: 0.0498


# 10: √(3^2 + 4^2)

Keystrokes:

HP 48S/48G/50g:
3 [LS] [ √ ] (x^2) 4 [LS] [ √ ] (x^2)

Display:
[2: 9.0000]
[1: 16.0000]

HP 48S/48G/50g:
[ + ] [√ ]

Display:
[1: 5.0000]

Result: 5

# 11: Find the percent change between 19.99 (old) and 34.99 (new)

%CHG = Δ% = [new - old] ÷ old x 100%

Keystrokes:

HP 48S:
19.99 [ENTER] 34.99 [MTH] [F1] (PARTS) [NXT] [F5] (%CH)

HP 48G:
19.99 [ENTER] 34.99 [MTH] [F5] (REAL) [F2] (%CH)

HP 50g:
19.99 [ENTER] 34.99 [LS] [SYMB] (MTH) [F5] (REAL) [F2] (%CH)

Result: 75.0375% change

Register Operations

Two common register operations are Swap and Roll Down.

Swap: This operation swaps the contents on the X and Y registers. The key is typically labeled [x<>y]. The swap function is useful when arguments need to be switched before performing subtraction, division, and taking powers.

# 12: 2 - (-5 x 3)

In order to demonstrate the Swap function, let's enter the multiplication first.

Keystrokes:

HP 48S/48G/50g:
5 [+/-] [ENTER] 3 [ x ]

Display:
[1: -15.000]

HP 48S/48G/50g:
2 [ENTER]

Display:
[2: -15.0000]
[1: 2.0000]

We need 2 on the top because we need to calculate 2 - (-5 x 3), not (-5 x 3) - 2. This is where the Swap operation comes in.

HP 48S/48G/50g:
[LS] [right arrow] (SWAP - not marked on the 50g+)

Display:
[2: 2.0000]
[1: -15.0000]

Now with the arguments in the proper order, we can execute the subtraction.

HP 48S/48G/50g:
[ - ]

Display:
[1: 17.0000]

Result: 17

# 13: Calculate 200 ÷ 40, but enter 40 first, then 200.

Here we can use the Swap operation to correct the order of dividend and divisor.

HP 48S/48G/50g:
40 [ENTER] 200

Display:
[1: 40.0000]
[ 200]

We need to swap the arguments.

HP 48S/48G/50g:
[ENTER] [LS] [left arrow]

Display:
[2: 200.0000]
[1: 40.0000]

Now we got it!

HP 48S/48G/50g:
[ ÷ ]

Display:
[1: 5.0000]

Result: 5

Roll Down: This operation pushes down the contents of the register one level. You choose how many of the levels "roll" down.


# 14 Roll down a three level stack.

A simple example: Say we have entered 4, 1, and 9 on to the stack and the stack is like this:

3: 4
2: 1
1: 9

((Clear Stack) 4 [ENTER] 1 [ENTER] 9 [ENTER])

I want to rotate the entire stack. The keystrokes for this is:

HP 48S:
[PRG] [F1] (STK) [F6] (DEPTH) [F4] (ROLLD)

HP 48G:
[LS] [up arrow] [F6] (DEPTH) [F4] (ROLLD)

HP 50g:
[LS] [EVAL] (PRG) [F1] (STACK) [NXT] [F6] (DEPTH) [F2] (ROLLD)

The stack looks like this:

3: 9
2: 4
1: 1


The Constant Pi (π)

The Pi key (or keystroke sequence) puts π on level 1 and lifts everything else one level.

# 15: Find the area of a circle with a radius of 2.35 inches.

Area = π *radius^2

Keystrokes:

HP 48S/48G/50g:
[LS] [SPC] (π) 2.35 [LS] [ √ ] (x^2) [ x ]

Display:
[1: 'π*5.5225']

HP 48S: [RS] [EVAL] (->NUM)
HP 48G: [LS] [EVAL] (->NUM)
HP 50g: [RS] [ENTER] (->NUM)

Display:
[1: 17.3494]

Result: 17.3494 square inches

Additional Examples

# 16: How many 5-card hands can be dealt out of a standard deck of 52 playing cards?

Combination = COMB = n! ÷ (k! x (n - k)!)

It is found in the Math-Probability Menu, labeled COMB

Keystrokes:

HP 48S:
52 [ENTER] 5 [MTH] [F2] (PROB) [F1] (COMB)

HP 48G:
52 [ENTER] 5 [MTH] [NXT] [F1] (PROB) [F1] (COMB)

HP 50g:
52 [ENTER] 5 [LS] [SYMB] (MTH) [NXT] [F1] (PROB) [F1] (COMB)

Result: 2,598,960 possible hands

# 17: You have purchased a calculator for $99.99 and present a coupon for 15% for the purchase price. Assume sales tax is 8.75%. What is the final amount due?

The percent function returns level 2 * level 1 ÷ 100 on level 1.

Keystrokes:

HP 48S:
99.99 [ENTER] [ENTER] 15 [MTH] [F1] (PARTS) [NXT] [F4] (%) [ - ] [ENTER] 8.75 [F4] (%) [ + ]

HP 48G:
99.99 [ENTER] [ENTER] 15 [MTH] [ F5 ] (REAL) [F1] (%) [- ] [ENTER] 8.75 [F1] (%) [ + ]

HP 50g:
99.99 [ENTER] [ENTER] 15 [LS] [SYMB] (MTH) [F5] (REAL) [F1] (%) [ -] [RS] [ENTER] (->NUM) [ENTER] 8.75 [F1] (%) [ + ]

Result: 92.4283 (The final bill is $92.43)

# 18: How to set the Angle Mode

HP 48S:
[LS] [CST] (MODES) [NXT] [NXT]
Select [F1] for Degrees, [F2] for Radians, [F3] for Gradients


HP 48G (via menu):
[RS] [CST] (MODES) [down arrow]
Use [F2] to choose the angle, press [F6] (OK) to accept the settings


HP 50g (via menu):
[MODE] [down arrow] [down arrow]
Use [F2] to choose the angle, press [F6] (OK) to accept the settings



# 19: While the calculator is in Radians mode, find sin^-1 (.5). Then convert the result to degrees.

See # 18 on how to set the calculator to Radians mode. Your calculator is in Radians mode if the display has a RAD indicator on the upper left corner of the screen.

HP 48S/48G/50g: .5 [LS] [SIN] (ASIN)

Display:
[1: 0.5236]

HP 48S: 180 [ x ] [LS] [SPC] (π) [ ÷ ] [RS] [EVAL]
HP 48G: [MTH] [F5] (REAL) [NXT] [NXT] [F6] (R->D)
HP 50g: [LS] [SYMB] (MTH) [F5] [NXT] [NXT] [F6] (R->D)

Display:
[1: 30.0000]

So sin^-1 (.5) ≈ .5236 radians = 30º

Note:
R->D is the Radians to Degrees function
D->R is the Degrees to Radians function

I hope you find this tutorial on RPL helpful.


Eddie

Wednesday, September 21, 2011

RPN Basics

RPN Basics
(updated 9/25/2011)

This is a basic tutorial of reverse polish notation (RPN).  RPN is an operating system that some calculators use, primarily those manufactured by Hewlett Packard.  RPN removes the need to enter parenthesis during long calculations and allows for immediate feedback during calculations; you will not need to enter a long operation before getting feedback - thus eliminating errors.  A lot of times, the number of keystrokes required to make a calculation is reduced using RPN compared to algebraic systems.

Typically, a RPN calculator uses a stack with four registers, named X, Y, Z, and T.  Each register is stacked on top of another.  A four-register stack diagram looks like this:

T
---
Z
---
Y
---
X [DISPLAY]                                                                                                                                         

Most displays will only show the contents of the X register. 

What is required of the user to execute a desired operation depends on the number of arguments (for our purpose, numbers) the function requires.  Most scientific calculator functions require one or two arguments.

One-argument functions operate on whatever is in the display, or the X register.  For one-argument functions, simply execute the desired operation.  One-argument functions include all the trigonometric functions (sine, cosine, tangent), logarithms, exponential (e^), reciprocal, square root, and factorial (x!).  The change sign operation fits under the category of one-number operations because it simply multiplies the number by -1.  The change sign operation is often labeled either CHS (HP 12C, HP 15C) or +/- (HP 35S).

Two-argument functions operate on the contents on the Y and X registers.  Common two-argument functions include the arithmetic operators (+, -, x, ÷), powers (y^x), combination and permutations, percent and percent change (Δ%).  To use a two-argument function, enter the first number (y), then press ENTER.  ENTER terminates the entry and gets the calculator ready to receive another number.  Next, enter the second number (x).  A second ENTER is not required because executing the operation terminates the second entry.  In summary, to operate a two-argument function:

1.  Enter the first (y) argument,
2.  Press ENTER to terminate the first entry.
3.  Enter the second (x) argument,
4.  Execute the desired function.

When you link more than one operation, it is known as a chain calculation.  A simple example is adding a list four numbers.   Another example is adding two groups of numbers and then multiplying the two sums together.

In chain calculations, whatever in the display becomes the first argument of the operation.  All that is needed is to enter the second argument (number), and then the required function.  For chain calculations:

1.  Enter the next required argument
2.  Execute the desired function, no ENTER is required

A more detailed explanation of the stack can be found in manuals of the HP 12C, 15C, and 35S calculators.     HP Website

The scope of this blog is just to give a very basic tutorial of RPN.  A lot of examples are provided to illustrate how to use the functions on an RPN calculator. 

Calculators with RPN

Hewlett Packard:
Scientific: 15C (including Limited Edition), 35S, 48 Series, 32Sii, 41C, 50g+, and many others
Financial: 12C (all editions), 30b

iPod Apps:
GO-Sci 25, GO-Sci 21, just to name a couple.

You can look for RPN calculators online, many are available for the iPod, iPad, and Android operating mobile devices.

This tutorial is going to be a "do by example" tutorial.  Keystrokes are shown in blue.  All calculations on this blog are rounded to 4 decimal places.

* Note: This works for most models.  In these examples, you may need to press a shift key to access an operation depending on the calculator.  Since this tutorial covers a variety of calculators, the shift keys are omitted.  Please check your manual.

Examples:  Calculating with RPN


#1:  5 + 8

Keystrokes:
5 [ENTER]       Display: 5.0000

8 [ + ]                Display: 13.0000


Result: 13


#2: 10 - 6
As in any calculation involving subtraction, the order is important.

Keystrokes:  
10 [ENTER]      Display: 10.0000

6 [ - ]                  Display: 4.0000


Result: 4

# 3:  6 x 2.95 + 2 x 1.28


Keystrokes:
6 [ENTER]       Display: 6.0000

2.95 [ x ]            Display: 17.7000

2 [ENTER]       Display:  2.0000

1.28 [ x ]            Display: 2.5600

[ + ]                    Display: 20.2600


Result: 20.26


# 4:  200 ÷ (3^2.5 - 1)

Keystrokes:
200 [ENTER]       Display:  200.0000

3 [ENTER]           Display: 3.0000

2.5 [y^x]               Display: 15.5885

1 [ - ]                     Display: 14.5885


[ ÷ ]                       Display: 13.7095

Result: 13.7095

# 5:  1/2 + 3/7 - √(25/64)


√ is the symbol for square root

Keystrokes (or one possible set of keystrokes):
2 [1/x]                   Display: 0.5000
3 [ENTER]           Display: 3.0000

7 [ ÷ ]                    Display: 0.4286

[ + ]                       Display: 0.9286
25 [ENTER]         Display: 25.0000

64 [ ÷ ]                  Display: 0.3906
[ √ ]                       Display: 0.6250

[ - ]                        Display: 0.3036

Result: 0.3036

# 6:  e^-3


Keystrokes:
3 [CHS] (or [+/-])      Display: -3
[e^x]                          Display: 0.0498


Result: 0.0498

# 7:  √(3^2 + 4^2)

Keystrokes:

If a square operation [x^2] is available:
3 [x^2]                    Display: 9.0000

4 [x^2]                    Display: 16.0000

[ + ]                         Display: 25.0000

[ √ ]                         Display: 5.0000

If a [x^2] is not available:
3 [ENTER] 2 [y^x]      Display: 9.0000

4 [ENTER] 2 [y^x]      Display: 16.0000

[ + ]                               Display: 25.0000

[ √ ]                               Display: 5.0000

Result: 5

# 8: Find the percent change between 19.99 (old) and 34.99 (new)

%CHG = Δ% =  [new - old] ÷ old x 100%

Keystrokes:

If a percent change function [Δ%] is available:
19.99 [ENTER]             Display: 19.9900

34.99 [Δ%]                    Display: 75.0375

If  [Δ%] is not available:
34.99 [ENTER] 19.99 [-]    Display: 15.0000

19.99 [÷]                              Display: 0.7504
100 [x]                                 Display: 75.0375


Result: The percent change is an increase of 75.0375%

Register Operations

Two common register operations are Swap and Roll Down.

Swap: This operation swaps the contents on the X and Y registers.  The key is typically labeled [x<>y].  The swap function is useful when arguments need to be switched before performing subtraction, division, and taking powers. 

#9:  2 - (-5 x 3)

Keystrokes:
5 [CHS] (or [+/-])       Display: -5
[ENTER] 3 [ x ]         Display: -15.0000
                                Display:  2       
[x<>y]                        Display: -15.0000
[ - ]                             Display: 17.0000

Result: 17

Roll Down:  This operation pushes down the contents of the register one level.

In a four stack scheme:
Whatever was in the T register goes to the Z register
Whatever was in the Z register goes to the Y register
Whatever was in the Y register goes to the X register
Whatever was in the X register goes to the T register

The key often labeled R with a down arrow next to it.  [R↓]

The Constant Pi (π)

The Pi key (or keystroke sequence) puts π on the X register (display) and lifts everything else one level.  On a four-register stack, whatever was held in the T register is lost.

#10: Find the area of a circle with a radius of 2.35 inches.

Area = π *radius^2

Keystrokes:
[π]                             Display: 3.1416

2.35 [x^2] [x]           Display: 17.3494


Result: 17.3494 square inches

Alternatively:  [ π ] 2.35 [ENTER] 2 [y^x] [ x ]

Additional Examples:

#11:  How many 5-card hands can be dealt out of a standard deck of 52 playing cards?

Combination = n! ÷ (k! x (n - k)!)

This function has several labels: Cy,x (HP 15C), COMB (HP 42S, HP 50g+), or nCr (most calculators)
The factorial function has several labels, typically x! or n!.

Keystrokes:

If a combination function is available:
52 [ENTER] 5 [nCr]

If a combination function is not available:
5 [x!]                                  Display: 120.0000

52 [ENTER]                      Display: 52.0000

5 [ - ]                                  Display: 47.0000

[x!]                                     Display: 2.5862     59   (2.5682 x 10^59)

[ x ] [1/x]                            Display: 3.2222    -62   (3.2222 x 10^-62)

52 [x!]                                Display: 8.0658      67  (8.0658 x 10^67)

[ x ]                                    Display: 2,598,960.000

Result: 2,598,960 possible 5-card hands

#12:  Find the sine of 30°

Keystrokes:
If necessary, set the calculator to degrees mode
30 [SIN]

Result: 0.5000

#13:  You have purchased a calculator for $99.99 and present a coupon for 15% for the purchase price.  Assume sales tax is 8.75%.  What is the final amount due?

In RPN calculators, the percent function [ % ] returns Y * X%.  The contents of the Y stack remain unchanged.

Keystrokes:
99.99 [ENTER] 15 [ % ]      Display: 14.9985   (99.99 x 15%)
[ - ]                                         Display: 84.9915
8.75 [ % ]                              Display: 7.4368     (84.9915 x 8.75%)
[ + ]                                        Display: 92.4283

Result: 92.4283 (The final bill is $92.43)

#14:  You deposit $1,000 in a bank account earning 3.5% interest for 5 years.  How much money will you have after 5 years?

FV = PV x (1 + i%)^n

Where FV is the future value, PV is the present value, i is the periodic interest rate, and n is the number of periods.  We are looking for FV with PV = 1,000, i = 3.5, and n = 5.

Keystrokes:
1000 [ENTER] 1 [ENTER] 3.5 [ % ]       Display: 0.0350

[ + ]                                                             Display: 1.0350

5 [ y^x ]                                                      Display: 1.1877

[ x ]                                                             Display: 1,187.6863

Result: 1,187.6863  ($1,187.68)


#15: On a right triangle, find the angle x in degrees:


                    /|
                  /  |
                /    |
        15  /      |
            /        |
          /x        |
         --------
               10

(my attempt at a right triangle, hopefully you get the picture)

x = arccos (10/15) = cos^-1 (10/15)

Keystrokes:

Set the calculator in Degrees mode if necessary.
10 [ENTER] 15 [ ÷ ]               Display: 0.6667
[COS^-1]                                Display: 48.1897

Result: The angle is 48.1897°


I hope you find this tutorial on RPN helpful.

Eddie

Many thanks to Xavier A. and Dieter on the MoHPC (The Museum of HP Calculators) Forum. 







Earth's Radius by Latitude

Earth's Radius by Latitude Introduction: Calculating the Earth’s Radius In quick, general calculations, we assume that the...