Element by Element Operations – Addition (+ or .+)

Tutorial Video

Addition of Scalars

Lets first look at the addition of scalars i.e. 1 by 1 matrices. Let's now for the sake of conceptualisation prescribe the values we have to objects. If we have 3 pens at home and order 5 more pens then when our order arrives we will have:

3 pens + 5 pens = 8 pens

\displaystyle \left[ {\text{3 pens}} \right]+\left[ {\text{5 pens}} \right]=\left[ {8\text{ pens}} \right]

\displaystyle \left[ 3 \right]+\left[ 5 \right]=\left[ 8 \right]

\displaystyle 3+5=8

To write this in MATLAB we would use

3+5

Addition of Column Vectors

Now let us conceptualise a more complicated example. Assume we have 3 pens and 2 pads at home, we then make a order for 5 more pens and 3 more pads.

Since pens and pads are separate objects we classify them as such. Let's essentially treat each item as a scalar:

3 pens + 5 pens = 8 pens

\displaystyle \left[ {\text{3 pens}} \right]+\left[ {\text{5 pens}} \right]=\left[ {8\text{ pens}} \right]

\displaystyle \left[ 3 \right]+\left[ 5 \right]=\left[ 8 \right]

\displaystyle 3+5=8

2 pads + 3 pads = 5 pads

\displaystyle \left[ {\text{2 pads}} \right]+\left[ {\text{3 pads}} \right]=\left[ {5\text{ pads}} \right]

\displaystyle \left[ 2 \right]+\left[ 3 \right]=\left[ 5 \right]

\displaystyle 2+3=5

If these are instead written as a column vector we will have:

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

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

To write this in MATLAB we would use

[3;2]+[5;3]

If I instead had 2 pens on my desk and I ordered 3 pads then in column vector notation I would have:

\displaystyle \left[ {\begin{array}{*{20}{c}} {\text{2 pens}} \\ {0\text{ pads}} \end{array}} \right]+\left[ {\begin{array}{*{20}{c}} {\text{0 pens}} \\ {3\text{ pads}} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {2\text{ pens}} \\ {3\text{ pads}} \end{array}} \right]

With this notation bare in mind that pens and pads are separate objects meaning a pen cannot transform into a pad and a pad cannot transform into a pen!

\displaystyle \left[ {\begin{array}{*{20}{c}} 2 \\ 0 \end{array}} \right]+\left[ {\begin{array}{*{20}{c}} 0 \\ 3 \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 2 \\ 3 \end{array}} \right]

To write this in MATLAB we would use

[2;0]+[0;3]

Note how we have to use zeros here to denote that we don't have a pad or pen in the first and second column vectors respectively. Element by Element operations will only work if the Arrays have the same amount of Elements. 

Addition of a Matrices

Okay so far, so good. Let's make things slightly more complicated now. Assume there are two neighbours, neighbour 1 lives in the red house and he has 3 pens and 2 pads, he makes an order for 5 pens and 3 pads and neighbour 2 lives in the green house and she has 2 pens and 2 pads, she makes an order for 7 pens and 5 pads. In this case after the order the man in the red house would have 8 pens and 5 pads whilst the woman would have 9 pens and 7 pads.

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

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

To write this in MATLAB we would use

[3,2;2,2]+[5,7;3,5]

Now obviously we can conceive of more complicated scenarios where there are say 5 neighbours and they each have and order 7 different item types of stationary which would give a 7 by 5 matrix opposed to the 2 by 2 case above.

Leave a Reply

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