Reference Guide

2-12 RPL Programming Examples
Techniques used in MEDIAN
Arrays, lists, and stack elements. MEDIAN extracts a column of data from
Σ
DAT in vector form. To convert
the vector to a list, MEDIAN puts the vector elements on the stack and combines them into a list. From this list
the median is calculated using %TILE.
The median for the mth column is calculated first, and the median for the first column is calculated last. As each
median is calculated, ROLLD is used to move it to the top of the stack.
After all medians are calculated and positioned on the stack, they’re combined into a vector.
FOR…NEXT (definite loop with counter). MEDIAN uses a loop to calculate the median of each column.
Because the medians are calculated in reverse order (last column first), the counter is used to reverse the order of
the medians.
Required Program
%TILE (page 2-10) sorts a list and returns the value of a specified percentile.
MEDIAN program listing (Note: Use approximate mode for this program and example).
Program: Comments:
«
RCLΣ
Puts a copy of the current statistics matrix
Σ
DAT on
the stack.
DUP SIZE
Puts the list { n m } on the stack, where n is the
number of rows in
Σ
DAT and m is the number of
columns.
OBJ→ DROP
Puts n and m on the stack, and drops the list size.
→ s n m
Creates local variables for s, n, and m.
«
'ΣDAT' TRN
Begins the defining procedure.
Recalls and transposes
Σ
DAT.
Now n is the number of columns in
Σ
DAT and m is
the number of rows. (To key in the
Σ
character, press
, then delete the parentheses.)
1 m
FOR j
Σ-
Specifies the first and last rows.
For each row, does the following: Extracts the last row
in
Σ
DAT.
Initially this is the mth row, which corresponds to the
mth column in the original
Σ
DAT.
(To key in the
Σ
command, use
.)
OBJ→ DROP
Puts the row elements on the stack. Drops the index
list { n }.
n →LIST
Makes an n-element list.
50 %TILE
Sorts the list and calculates its median.
j ROLLD
Moves the median to the proper stack level.
NEXT
Increments j and repeats the loop.