Practical 3: Arrays

Arrays

One-Dimensional Operations

MATLAB has a specific array or ‘element-by-element’ multiplication, •*, designed for one-dimensional arrays, that is also called ‘Hadamard product’ in mathematics, and uses a dot, •, before multiply sign, *, eg V1•*V2

array dot

Exercise: Multiplication with Arrays

 

> First define A=linspace(0,5,11) and B=linspace(1,6,11), c=4, and d=-1


> Find out what happens if you run the following equations:

A*c+d

A*c+d*B

> What happens if you multiply?

A*B

Note: MATLAB sends you an error message that ‘Matrix dimensions should agree’. It means that you forgot to use a dot before the multiplication sign. Matrix multiplication MATLAB referred to will be taught in further courses.

> Try it again with a dot to perform array multiplication:

A.*B

> Type in the following commands to find out which one works.

A*5               A.*5               5*A

A/5                5/A               5./A

A^2               2^A                2.^A