Commodore 2001-8 User Manual page 55

Table of Contents

Advertisement

1
~
~
2
~
~
3
"""
~
We have created by this example a multi-dimensional subscripted variable. These arrays correspond to
matrices used in mathematics.
In mathematics, a vector is an ordered collection of numbers:
The above vector has n components and is called a vector of dimension n.
For example,
~(3,9,2)
is a vector of dimension 3.
Order is imporatant here since
if
w~(3,2,9)
W=Fv.
Vectors can be stored in memory using subscripted variables. These variables are used in the same way
as the variables we have seen so far -X, 1%, A$, etc. That is, they call whatever value is stored in that
variable or return a zero or null (" ") if the value has not been previously specified.
Like vectors, subscripted variables have the power to execute a large number of operations using a single
notation. They are especially useful when combined with FOR-NEXT loops as the next example shows.
Example: Dot Product
The dot product of two vectors v
&
w is a vector, denoted by v. w, whose ith component (v.w), is
v,
x
W,.
I
I
I
For example, in the four dimensional case, if
and w=(w" w
2 ,
w
J ,
w~)
Then
v·w =
(V1
X W" V 2 X
w
2 , V3 X
w
3 ,
V4
X
w~)
Suppose we had
v=(5,6,7,11,4,6,11
w
=
(9,5,2,1,0,3,2)
Then a program to compute the dot product v • w might look like
FOR I
=
1 TO 7:READ V(I):NEXT
FOR I
=
1 TO 7:READW(I):NEXT
FOR I
=
1 TO 7:VW(I)
=
V(I)·W(I):NEXT
FOR I
=
1 TO 7:?VW(I):N EXT
51

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents