OKPEDIA MATLAB EN VETTORI

How to subtract vectors in Matlab and Octave

To subtract two vectors on Matlab and Octave use the minus operator (-)

v + w

The terms v and w are two vectors.

Example

Example 1

Define a vector v

>> v=[1;9;4]

Define another vector w

>> w=[4;5;6]

They are two column vectors with three elements.

To calculate the difference between the two vectors write v-w

>> v-w
ans =
-3
4
-2

The result is the difference vector

$$ v-w = \begin{pmatrix} 1 \\ 9 \\ 4 \end{pmatrix} - \begin{pmatrix} 4 \\ 5 \\ 6 \end{pmatrix} = \begin{pmatrix} 1 - 4 \\ 9 - 5 \\ 4 -6 \end{pmatrix} = \begin{pmatrix} - 3 \\ 4 \\ -2 \end{pmatrix} $$

https://how.okpedia.org/en/matlab/how-to-subtract-vectors-in-matlab-and-octave


Report us an error or send a suggestion to improve this page


Arrays and Vectors


FacebookTwitterLinkedinLinkedin