Radio Shack TRS-80 Model 100 Basic Manual page 99

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

LIST the program; you should now have:
10 CLS
20 N ;; 24
25 DIM Y(24)
30 FOR X ;; 1 TO N
50 READ Y(X)
60 SX
=
SX
+
X:XX
=
XX
+
X*X
70 SY
=
SY
+
Y(X):XY
=
XY
+
X*Y(X)
80 NEXT X
90 B
=
(N*XY - SX*SY) /
(N*XX - SX*SX)
100 A
=
(SY - B*SX) / N
110 PRINT "FORECAST FOR PERIOD X IS"
120 PRINT Aj"
+
"j6j" * X"
200 DATA 160, 175, 1.40, 230
210 DATA 155, 215, 155, 225
220 DATA 215, 265, 220, 325
230 DATA 225, 270, 265, 290
240 DATA 275, 350, 255, 345
250 DATA 300, 330, 315, 380
Suppose the data in lines 200 through 250 represent quarterly sales figures for six
consecutive years. RUN the program to compute the trend line on the 24 quarters of
data. You will not have to enter any data during execution, since the program reads
the data from the DATA satements. If you have entered the program changes and data
correctly, you will see the trend line equation:
FORECAST FOR PERIOD X IS
148.22463768116
+
8.4086956521739
*
X
Of course, the time period assumed here is a quarter, so that the equation will predict
the sales for a specified quarter in the future. For example, to predict the first quarter
of year seven (period 25), enter:
PRINT 148.225
+
8.4087 * 25
(The numbers are rounded off to three or four decimal places.) The result, 358.4425
which is displayed represents the trend line projection of sales to the next period in the
future.
A new type of variable, the subscripted variable, has been introduced in this
experiment. While this experiment could have been performed without the use of a
subscripted variable, including it now will make the next experiment much easier.
The DIM Y(24) statement in line 25 defines the variable Y as a subscripted variable
having a maximum of 24 storage locations allocated to it. These 24 storage locations
can be thought of as 24 separate variables:
YO), Y(2), Y(3), . . . . Y(24)
The number within the parentheses is called the SUbscript, and refers to the relative
position of the variable within the block of storage locations set aside by the
corresponding DIM (for "DIMension") statement. The block of storage locations is
called the Y array. Thus, the variable Y(X), used in lines 50 and 70, refers to
position X within the Y array.
93

Advertisement

Table of Contents
loading

Table of Contents