aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/VECTOR.ht
blob: 13be70a14f030e170c116cf063e11061c7cbef34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\VectorXmpTitle}{Vector}
\newcommand{\VectorXmpNumber}{9.85}
%
% =====================================================================
\begin{page}{VectorXmpPage}{9.85 Vector}
% =====================================================================
\beginscroll


The \spadtype{Vector} domain is used for storing data in a one-dimensional
indexed data structure.
A vector is a homogeneous data structure in that all the components of the
vector must belong to the same \Language{} domain.
Each vector has a fixed length specified by the user; vectors are not
extensible.
This domain is similar to the \spadtype{OneDimensionalArray} domain,
except that when the components of a \spadtype{Vector} belong to a
\spadtype{Ring}, arithmetic operations are provided.
For more examples of operations that are defined for both
\spadtype{Vector} and \spadtype{OneDimensionalArray}, see
\downlink{`OneDimensionalArray'}{OneDimensionalArrayXmpPage}\ignore{OneDimensionalArray}.

As with the \spadtype{OneDimensionalArray} domain, a \spadtype{Vector} can
be created by calling the operation \spadfunFrom{new}{Vector}, its components
can be accessed by calling the operations \spadfunFrom{elt}{Vector} and
\spadfunFrom{qelt}{Vector}, and its components can be reset by calling the
operations \spadfunFrom{setelt}{Vector} and
\spadfunFromX{qsetelt}{Vector}.
\xtc{
This creates a vector of integers of length
\spad{5} all of whose components are \spad{12}.
}{
\spadpaste{u : VECTOR INT := new(5,12) \bound{u}}
}
\xtc{
This is how you create a vector from a list of its components.
}{
\spadpaste{v : VECTOR INT := vector([1,2,3,4,5]) \bound{v}}
}

\xtc{
Indexing for vectors begins at \spad{1}.
The last element has index equal to the length of the vector,
which is computed by \spadopFrom{\#}{Vector}.
}{
\spadpaste{\#(v) \free{v}}
}
\xtc{
This is the standard way to use \spadfunFrom{elt}{Vector} to extract an
element.
Functionally, it is the same as if you had typed \spad{elt(v,2)}.
}{
\spadpaste{v.2 \free{v}}
}
\xtc{
This is the standard way to use \spadfunFrom{setelt}{Vector} to change an
element.
It is the same as if you had typed \spad{setelt(v,3,99)}.
}{
\spadpaste{v.3 := 99 \free{v}\bound{vdelta}}
}
\xtc{
Now look at \spad{v} to see the change.
You can
use \spadfunFrom{qelt}{Vector} and \spadfunFromX{qsetelt}{Vector} (instead
of \spadfunFrom{elt}{Vector} and \spadfunFrom{setelt}{Vector},
respectively) but {\it only} when you know that the index is within the valid
range.
}{
\spadpaste{v \free{vdelta}}
}

\xtc{
When the components belong to a \spadtype{Ring}, \Language{}
provides arithmetic operations for \spadtype{Vector}.
These include left and right scalar multiplication.
}{
\spadpaste{5 * v \free{vdelta}}
}
\xtc{
}{
\spadpaste{v * 7 \free{vdelta}}
}
\xtc{
}{
\spadpaste{w : VECTOR INT := vector([2,3,4,5,6]) \bound{w}}
}
\xtc{
Addition and subtraction are also available.
}{
\spadpaste{v + w \free{vdelta w}}
}
\xtc{
Of course, when adding or subtracting, the two vectors must have the same
length or an error message is displayed.
}{
\spadpaste{v - w \free{vdelta w}}
}

For more information about other aggregate domains,
see the following:
\downlink{`List'}{ListXmpPage}\ignore{List},
\downlink{`Matrix'}{MatrixXmpPage}\ignore{Matrix},
\downlink{`OneDimensionalArray'}{OneDimensionalArrayXmpPage}\ignore{OneDimensionalArray},
\downlink{`Set'}{SetXmpPage}\ignore{Set},
\downlink{`Table'}{TableXmpPage}\ignore{Table}, and
\downlink{`TwoDimensionalArray'}{TwoDimensionalArrayXmpPage}\ignore{TwoDimensionalArray}.
Issue the system command \spadcmd{)show Vector}
to display the full list of operations defined by
\spadtype{Vector}.

\endscroll
\autobuttons
\end{page}
%