Tuesday, October 11, 2011

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.