Element by Element Operations – Subtraction (- or .-)

Tutorial Video

Element by Element Subtraction

Array subtraction works in an identical manner to element by element subtraction therefore it does not matter if we use - or .-.

Subtraction of Scalars

The items we illustrated are consumables. Taking the case of scalars, in this case only looking at pens, assuming we have 8 pens and use 6 of them up writing then after we put the 6 used up pens in the recycle bin we are left with:

8 pens - 6 pens = 2 pens

\displaystyle \left[ {\text{8 pens}} \right]-\left[ {\text{6 pens}} \right]=\left[ {2\text{ pens}} \right]

\displaystyle \left[ 8 \right]-\left[ 6 \right]=\left[ 2 \right]

\displaystyle 8-6=8

To write this in MATLAB we would use

8-6

Subtraction of Column Vectors

If we started off with 8 pens and 5 pads and used up 6 pens and 3 pads then

Written as a column vector we will have:

\displaystyle \left[ {\begin{array}{*{20}{c}} {\text{8 pens}} \\ {\text{5 pads}} \end{array}} \right]-\left[ {\begin{array}{*{20}{c}} {\text{6 pens}} \\ {3\text{ pads}} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {2\text{ pens}} \\ {2\text{ pads}} \end{array}} \right]

\displaystyle \left[ {\begin{array}{*{20}{c}} 8 \\ 5 \end{array}} \right]-\left[ {\begin{array}{*{20}{c}} 6 \\ 3 \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 2 \\ 2 \end{array}} \right]

To write this in MATLAB we would use

[8;5]-[6;3]

Subtraction of a Matrices

Okay so far, so good. Let's make things slightly more complicated again the man living in the red house has 8 pens and 5 pads and consumes 6 pens and 3 pads and the woman has 9 pens and 7 pads and consumes 8 pens and 4 pads. The man should therefore be left with 2 pens and 2 pads while the woman should be left with 1 pen and 3 pads

\displaystyle \left[ {\begin{array}{*{20}{c}} {\text{8 pens}} & {9\text{ pens}} \\ {\text{5 pads}} & {\text{7 pads}} \end{array}} \right]+\left[ {\begin{array}{*{20}{c}} {\text{6 pens}} & {\text{8 pens}} \\ {\text{3 pads}} & {4\text{ pads}} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {\text{2 pens}} & {\text{1 pens}} \\ {2\text{ pads}} & {3\text{ pads}} \end{array}} \right]

\displaystyle \left[ {\begin{array}{*{20}{c}} 8 & 9 \\ 5 & 7 \end{array}} \right]+\left[ {\begin{array}{*{20}{c}} 6 & 8 \\ 3 & 4 \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 2 & 1 \\ 2 & 3 \end{array}} \right]

To write this in MATLAB we would use

[8,9;5,7]-[6,8;3,4]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.