To execute a function on every element of a list – HP 49g Graphing Calculator User Manual
Page 89
Attention! The text in this document has been recognized automatically. To view the original document, you can use the "Original mode".
![background image](/manuals/632032/89/background.png)
Example:
Find the 2-element moving average of {2, 4, 8, 16, SOj.
1. Enter the list.
2. Enter the frame index.
In this example, the number is 2, as you want to find the average of tv)o
nimibers each time.
3. Enter the program.
« +
2
/ »
4. Execute the
DOSUB
command.
0
{mg) LIST PROCEDURES DOSIJBS.
The answer is ¡3, 6, 12, 33).
To execute a function on every element of a list
The
STREAM
command enables you to apply a fimction I'ecursively to every
element in a list. The command takes the first two elements, executes a
function, takes the result and the next element, executes the fimction
again, and so on, until there are no more arguments for the function to
work on.
In RPN mode, the steps are:
1. Enter the list.
For example, { 1 2 3 4 5).
2. Enter a program or fimction that takes two arguments and returns one
result.
For example, « * ».
3. Execute
STREAM.
0
® LIST PROCEDURES STREAM.
hr this example, the fimction multiplies all the elements in the list. The
answer is 120.
You can also use the product list command to calculate the product of all
the elements in a list. See “To find the product of the elements in a finite
list” on page 9-10.
Page 9-6
Lists and Sequences