For all models

R. C. Bahn fractional differences between terms. These two programs demonstrate that the FOR-NEXT statement is merely an automation of finite arithmetic series for the control of a programmed loop'.

The sum of a collection or set of numbers may be computed by first setting a variable equal to zero outside a loop (140, 260, 370, 500, 600) and then incrementing this variable by the proper value during each pass of the loop (150, 280, 390, 530, 630). Note especially the appearance of the previous list of lines (150-630). These lines do not denote mathematical equality. The lines illustrate the assignment role of the equal sign {=) in the BASIC language. In this sense, each of the indicated lines should be interpreted as meaning: assign to the new variable, for example N, a value which consists of the previous value of N plus the indicated increment.

In the second and third subprograms (190-420), the sum of the generated arithmetic series is found by the above method (280, 390). The sum is displayed after adding each new term of the series (290, 400). The sum of a finite arithmetic series of length N may also be computed by the formula:

In the fourth subprogram (430-670) the concept of the sum is extended to the computation of the mean (540) and the standard deviation (650). The set of numbers to be studied are entered from the keyboard in a loop extending from line 440 to 490. The mean or average is a measure of the central tendency of the set of numbers. The standard deviation is a measure of a variability or dispersion of the set of numbers. Additional comments concerning the function of each line of the program appear in a latter section.


Study the construction of the programs carefully. You should be able to modify the simple counting program so that it can count forwards or backwards by any integer difference.

The outputs of the arithmetic series programs

110 80-U.S. Journal, January, 1982

are identical. Compare the programs and identify the statements in the second subprogram which serve the function of the FOR-NEXT statements of the third sub-program.

The routines for the mean and standard deviation are useful programs. The SUM of this program could be used to balance the checkbook or add the grocery bill. The MEAN might be useful in the analysis of your golf scores or school grades. The functions of several of the loops in the last program can be combined into one loop and the standard deviation can be computed by an alternate formula. These methods can readily be found in any handbook of statisitics.

Program Documentation of 'loop*

Line # Comment

10 - 180 Driver program 30 Label

110 Check limits of input 120 Branch to appropriate program 130-180 Simple counting loop routine 140 Initialize 150 Increment N 160 Output results 170 Test for end of loop 190 - 310 Arithmetic series routine 210 - 230 Input parameters of series

240 Label columns of output 250 - 260 Initialize NUM, N, SUM 270:1 Increment NUM 270:2 Test for end of increasing or decreasing series 320 - 420 FOR-NEXT loop routine 340 - 360 Input parameters of loop

370:1 Initialize N counter needed for auxiliary loop index 370:2 Initialize SUM 375 Print column headings 380 - 410 The loop

390 Increment N and SUM 400 Output results 430 - 670 Mean and standard deviation routines

440 - 460 Initial data collection routine 460 Reconcile length of list with dimensions of X(J) 470 - 490 Interactive keyboard data entry 500 Initialize SUM 510 Print column headings 520 - 570 FOR-NEXT loop to compute SUM and MEAN 530 Accumulate SUM 540 Compute cumulative average 550 Print current results 560 Hold screen every 12 lines for sequential inspection 580 - 590 Save final SUM and AVERAGE

600 Initialize SUM of squared deviations from mean (SSQ) 610 FOR-NEXT loop to compute standard deviation 620 Compute deviation from mean 630 Accumulate sum of squared deviations (SSQ) 650 Compute standard deviation

(root mean square) 660 Print separating graphics line 670 Print results

Program listing for Models I, II & III

10 clear 500 : dim xc100)

20 cls

30 print " basic inter actions by r.c.bahn"


TheSO-U.S. Journal

Was this article helpful?

0 0

Post a comment