Element by Element Operations – Multiplication (.*)

Tutorial Video

Element by Element Multiplication

Element by element multiplication (the dot product) .* works differently from Array multiplication * be careful not to confuse the two.

Multiplication of Scalars

Assuming one buys 5 pens and the price of a pen is £2. Then the amount of cash spent on pens is £10

5 pens .* £2 = 5*£2 = £10

\displaystyle \left[ 5 \right].*\left[ {\pounds2} \right]=\left[ {5*\pounds2} \right]=\left[ {\pounds10} \right]

To write this in MATLAB we would use

5.*2

Note for a 1 by 1 scalar array multiplication and element by element multiplication are identical.

(Dot Product) of Column Vectors

If we ordered 5 pens which cost £2 each and 3 pads which cost £6 each then

\displaystyle \left[ {\begin{array}{*{20}{c}} 5 \\ 3 \end{array}} \right].*\left[ {\begin{array}{*{20}{c}} {\pounds2} \\ {\pounds6} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {5*\pounds2} \\ {3*\pounds6} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {\pounds10} \\ {\pounds18} \end{array}} \right]

\displaystyle \left[ {\begin{array}{*{20}{c}} 5 \\ 3 \end{array}} \right].*\left[ {\begin{array}{*{20}{c}} 2 \\ 6 \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {5*2} \\ {3*6} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {10} \\ {18} \end{array}} \right]

i.e. we would spend a total of £10 on pens and £18 on pads.

To write this in MATLAB we would use

[5;3].*[2;6]

(Dot Product) of Matrices

If the man in the red house bought 5 pens and 3 pads and the women in the green house bought 7 pens and 5 pads from the same shop costing £2 a pen and £6 a pad then:

\displaystyle \left[ {\begin{array}{*{20}{c}} {5\text{ pens}} & {7\text{ pens}} \\ {3\text{ pads}} & {5\text{ pads}} \end{array}} \right].*\left[ {\begin{array}{*{20}{c}} {\pounds2} & {\pounds2} \\ {\pounds6} & {\pounds6} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {5*\pounds2} & {7*\pounds2} \\ {3*\pounds6} & {5*\pounds6} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {10} & {14} \\ {18} & {30} \end{array}} \right]

\displaystyle \left[ {\begin{array}{*{20}{c}} 5 & 7 \\ 3 & 5 \end{array}} \right].*\left[ {\begin{array}{*{20}{c}} 2 & 2 \\ 6 & 6 \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {\pounds10} & {\pounds14} \\ {\pounds18} & {\pounds30} \end{array}} \right]

i.e. the man spent £10 on pens and £18 on pads and the woman spent £14 on pens and £30 on pads.

To write this in MATLAB we would use

[5,7;3,5].*[2,2;6,6]

Alternatively if the woman living in the green house went to a more expensive shop where the price of pens and pads was £3 and £7 respectively

 

\displaystyle \left[ {\begin{array}{*{20}{c}} {5\text{ pens}} & {7\text{ pens}} \\ {3\text{ pads}} & {5\text{ pads}} \end{array}} \right].*\left[ {\begin{array}{*{20}{c}} {\pounds2} & {\pounds3} \\ {\pounds6} & {\pounds7} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {5*\pounds2} & {7*\pounds3} \\ {3*\pounds6} & {5*\pounds7} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {\pounds10} & {\pounds21} \\ {\pounds18} & {\pounds35} \end{array}} \right]

\displaystyle \left[ {\begin{array}{*{20}{c}} 5 & 7 \\ 3 & 5 \end{array}} \right].*\left[ {\begin{array}{*{20}{c}} 2 & 3 \\ 6 & 7 \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} {10} & {21} \\ {18} & {35} \end{array}} \right]

i.e. the man would once again spend £10 on pens and £18 on pads and this time the woman would spend £21 on pens and £35 on pads.

To write this in MATLAB we would use

[5,7;3,5].*[2,3;6,7]

Leave a Reply

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