How to add vectors in Matlab and Octave
To add two vectors on Matlab and Octave use the operator +
v + w
The terms v and w are two vectors.
Example
Example 1
Define a vector v
>> v=[1;2;3]
Define another vector w
>> w=[4;5;6]
They are two column vectors with three elements.
To add the two vectors write v + w
>> v+w
ans =
5
7
9
The result is the sum vector
Example 2
Define a row vector
>> z=[1 2]
z = 1 2
Define a column vector
>> u=[3;4]
u =
3
4
Add the two vectors z + u
>> z+u
The output result is
ans =
4 5
5 6
Note. In this case the result is a matrix because the sum is between a row vector and a column vector $$ z+u = \begin{pmatrix} 1 & 2 \end{pmatrix} + \begin{pmatrix} 3 \\ 4 \end{pmatrix} = \begin{pmatrix} 1+3 & 2+3 \\ 1+4 & 2+4 \end{pmatrix} = \begin{pmatrix} 4 & 5 \\ 5 & 6 \end{pmatrix} $$
