Step 3: Define a local variable to keep track of the sum of the terms in List
Type sum in the placeholder on the second line of the program
Left-click on the Programming menu and then left-click on to insert a Local Assignment symbol
Type 0 and hit Enter to add a new line to the function definition
Step 4: Create a for loop in the program to calculate the average of the terms in List
With the blue cursor in the placeholder on the third line Left-Click on the Programming icon
Left-Click on for in the Programming toolbar. Mathcad will insert a template for defining a for loop
The for loop template has placeholders
for the name of the counter variable, the
range of values for the counter, and the
body of the loop. The body can be one
or more lines.
Step 5: Complete the values in the template for the for loop
In the first placeholder type count, the name given to our local variable for controlling the loop
Create a range variable: In the second placeholder type 0,
Mathcad will insert a template for a range variable as shown below:
In the first empty placeholder for the range variable type 1
In the second placeholder for the range variable type Terms - 1
Left-Click in the placeholder for the body of the for loop
Important Note: The list of terms to be averaged will
be passed to the program as an nx1 matrix, so count
will also be used as a matrix subscript to refer to
each element in the matrix. By default, Mathcad
defines the first position in an array as position 0.
Programming with Mathcad Prime | pg. 7