Pulsars
0 %
Log inSign up

Notation and basic operations

Addition and multiplication by a scalar

Adding two matrices

You can only add two matrices of the same size (same number of rows and same number of columns). Addition is done coefficient by coefficient, at the same position.

Addition (cell by cell):

  [ 1  2 ]     [ 5  6 ]     [ 1+5  2+6 ]     [ 6   8  ]
  [ 3  4 ]  +  [ 7  8 ]  =  [ 3+7  4+8 ]  =   [ 10  12 ]

(each cell of the result = sum of the cells at the same place)

Multiplication by a scalar

A scalar is simply a number (as opposed to a matrix). Multiplying a matrix by a scalar k amounts to multiplying each coefficient by k.

Multiplication by the scalar k = 3:

           [ 1  2 ]     [ 3*1  3*2 ]     [ 3  6 ]
  3  x     [ 3  4 ]  =  [ 3*3  3*4 ]  =   [ 9  12 ]

(each cell is multiplied by the same number 3)

Useful properties

These two operations behave like on ordinary numbers: addition is commutative (A + B = B + A) and associative, and multiplication by a scalar is distributive over addition: k x (A + B) = k x A + k x B. There is also the zero matrix (all coefficients equal to 0), which plays the neutral role for addition.

Combined example

With A = [[1,2],[3,4]] and B = [[5,6],[7,8]], let us compute 2A - B, that is 2A + (-1)B:

2A = [[2,4],[6,8]], and -B = [[-5,-6],[-7,-8]], so 2A - B = [[2-5, 4-6],[6-7, 8-8]] = [[-3,-2],[-1,0]].

Common pitfall

You cannot add two matrices of different sizes (for example a 2 x 3 and a 3 x 2): the operation is simply not defined, even if the total number of coefficients is identical. Always check the sizes before adding.