Vectors
Vectors are created "on demand". If a vector, or vector element, appears on the left hand side of an
assignment statment then a vector of sufficient size is created to implement the assignment.
For example,
>>V(5) = 3.0;
assigns the value 3.0 to the
(5) element of V. If V is not of sufficient size, then V is redimensioned
to a vector of length 5 to accomodate the assignment. .
Elements of the vector are accessed using ()'s. A range of indices can be accessed using the : notation, e.g. V(1:3)
refers the first three elements of V collectively.
Indexing starts at 1.
The default storage of vectors are as "row" vectors (e.g. 1 x N matrices).
length(V) returns the size of the vector V.
The transpose of a vector can be obtained using the ' operator, or the transpose function.
Element by element operations are implement with the "dot" operators
.+ .- .* ./ .^
If two vectors are not compatable sizes for an algebraic operation, then an error message is generated.
Alternate methods of vector construction can be obtained using []'s. Commas separate vector entries and semi-colons
separate rows..
See Also : Operators
Samples
% creating a vector of length 3 initialized to 0.0
V(3) = 0.0 V = 0 0 0
% range access
V(1:2) = 5.0 V = 5 5 0
% create vectors using []'s
V = [1,2,3,4] % commas separate row entries V = 1 2 3 4 W =[1;2;3;4] % semi-colons separate rows W = 1 2 3 4
% create a vector using the range command
z = 0.0:.2:1.0 z = 0 0.2000 0.4000 0.6000 0.8000 1.0000
UCLA Mathematics Department | ©2000 |