Numerical Operands

The expression x + y produces the sum of x and y when they are two scalars (either doubles, integers, or bytes).

If A and B are matrices of the same dimensions, A + B is a matrix of same dimension whose entries are the sums of the corresponding entries of A and B.

If either A or B is scalar (1 x 1 matrix), then the scalar is added to each entry of the other matrix.

If A is an matrix and B is row vector, when A+B is calcuated, the th element of B is added to each element of the th row of A.

Similarly, if A is an matrix and B is column vector, when A+B is calcuated, the th element of B is added to each element of the th column of A.

If the dimensions of A and B don't match in any of the ways described above, A + B will cause an error. For example

    x = [-2.5, 3; 9, 7]
        -2.5    3
           9    7
    y = [1, -2; 3, -5]
           1    -2
           3    -5
    z = x + y
           -1.5  1
             12  2

If A and B are of the same storage type, then A + B is of the same type. Otherwise the type of the result is same as the one that needs more storage space. For example, if a double matrix and a integer matrix are added, the result is a double matrix.

Subtraction A - B is defined in the similar manner.

oz 2009-12-22