--> v=[2,-3+%i,7] v = ! 2. - 3. + i 7. ! --> v' ans = ! 2. ! ! - 3. - i ! ! 7. ! --> w=[-3;-3-%i;2] w = ! - 3. ! ! - 3. - i ! ! 2. ! --> v'+w ans = ! - 1. ! ! - 6. - 2.i ! ! 9. ! --> v*w ans = 18. --> w'.*v ans = ! - 6. 8. - 6.i 14. !Notice that vector elements that are separated by commas (or by blanks) yield row vectors and those separated by semi-colons give column vectors. The empty matrix is
[]
; it has zero rows and zero columns.
Note also that a single quote is used for transposing a
vector
(one obtains the complex conjugate for complex entries). Vectors of same
dimension can be added and subtracted. The scalar product of a row and
column vector is demonstrated above. Element-wise
multiplication (.*) and division (./) is also possible
as was demonstrated.
Note with the following example the role of the position of the blank:
-->v=[1 +3] v = ! 1. 3. ! -->w=[1 + 3] w = ! 1. 3. ! -->w=[1+ 3] w = 4. -->u=[1, + 8- 7] u = ! 1. 1. !
Vectors of elements which increase or decrease incrementely are constructed as follows
--> v=5:-.5:3 v = ! 5. 4.5 4. 3.5 3. !The resulting vector begins with the first value and ends with the third value stepping in increments of the second value. When not specified the default increment is one. A constant vector can be created using the ones and zeros facility
--> v=[1 5 6] v = ! 1. 5. 6. ! --> ones(v) ans = ! 1. 1. 1. ! --> ones(v') ans = ! 1. ! ! 1. ! ! 1. ! --> ones(1:4) ans = ! 1. 1. 1. 1. ! --> 3*ones(1:4) ans = ! 3. 3. 3. 3. ! -->zeros(v) ans = ! 0. 0. 0. ! -->zeros(1:5) ans = ! 0. 0. 0. 0. 0. !Notice that ones or zeros replace its vector argument by a vector of equivalent dimensions filled with ones or zeros.