The following arithmetic operations are defined in MATLAB:

1) addition +

2) subtraction –

3) multiplication *

4) division /

5) elevation to power

When the expression to be evaluated is too long to fit on a single command line, it is possible to use a continuation character given by. . . (three points). Eg:

>> 1 + 1/4 + …

1/8

ans =

1.3750

It is possible to verify that since in MATLAB there is no distinction between whole, real or complex variables, the result of the operation of elevation to power in the case of fractional exponents may not correspond to that naturally expected. For example, if you want to calculate the cubic root of -5, you get:

>> (-9) ^ (1/5)

ans =

1.2555 + 0.9122i

then an imaginary number instead of a real number. The problem is due to the fact that MATLAB, working in complex notation, calculates as the first cubic root of -9 one of the two with non-imaginary imaginary part.

Also in MATLAB it is possible to alter the classical precedences of the arithmetic operations through the appropriate use of the round brackets. For example, if in the previous case we had written (- 9) * 1/5 we would have obtained the value -1.8000 that is, correctly, – 9/5.

>> (- 9) * 1/5

ans =

-1.8000

As far as the vectors are concerned, elementary operations extend (when well defined) in a completely natural way, with the exception of division and power-up operations. Eg,

>> a = [1: 4];

>> b = [1: 3];

>> c = [3 2 6 -1];

>> a + c (sum of row carriers)

ans =

4 4 9 3

>> a-c (line array difference)

ans =

-2 0 -3 5

>> a + b

??? Error using ==> plus

Matrix dimensions must agree.

>> a * c

??? Error using ==> mtimes

Inner matrix dimensions must agree.

The last instructions show us that the operations between vectors are valid only if the dimensions are consistent. In fact, given a line vector s of dimension n (ie a matrix 1 * n) and a vector column d of size m, we can execute the scalar product s * d only if m = n (obtaining in this case a scalar).

>> s = [1: 4];

>> d = [1; 2; 3; 4];

>> s * d

ans =

30

So d * s will provide a m * n matrix.

>> s = [1: 4];

>> d = [1; 2; 3; 4];

>> M = d * s

M =

1 2 3 4

2 4 6 8

3 6 9 12

4 8 12 16