RPL Programming 1-25
Using Summations Instead of Loops
For certain calculations that involve summations, you can use the Σ function instead of loops. You can use Σ
with stack syntax or with algebraic syntax. Σ automatically repeats the addition for the specified range of the
index variable — without using a loop structure.
Example: The following programs take an integer upper limit n from the stack, then find the summation. One
program uses a FOR … NEXT loop — the other uses Σ.
Program: Comments:
"!
8!3!KL:!
7LK!^!
^!DU!'!
=<T:
Initializes the summation and puts
the limits in place.
Loops through the calculation.
»
Program: Comments:
"!
#!G!
+\-^[3FGF^WH/+
Uses Σ to calculate the summation.
»
Example: The following program uses ΣLIST to calculate the summation of all elements of a vector or matrix.
The program takes from the stack an array or a name that evaluates to an array, and returns the summation.
Program: Comments:
"!
LS_#!
3!
'!
`E6D:!
#E6D:!
\E6D:
Finds the dimensions of the array and
leaves it in a list on level 1.
Adds 1 to the list. (If the array is a vector,
the list on level 1 has only one element.
ΠLIST will error if the list has fewer than
two elements.)
Multiplies all of the list elements together.
Converts the array elements into a list, and
sums them.
»
Using Flags
You can use flags to control calculator behavior and program execution. You can think of a flag as a switch that
is either on (set) or off (clear). You can test a flag's state within a conditional or loop structure to make a
j
2
j 1=
n
∑