Matrix Addition#

Matrix addition is simple: add corresponding elements together.

The Basic Idea#

To add two matrices, add each element with its partner in the same position:

\[\begin{split} \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} = \begin{bmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{bmatrix} = \begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix} \end{split}\]

Element-by-Element#

More formally, if \(C = A + B\), then each element \(c_{ij}\) is:

\[ c_{ij} = a_{ij} + b_{ij} \]

The element in row \(i\), column \(j\) of \(C\) equals the sum of the corresponding elements from \(A\) and \(B\).

In Python#

Python Example

Add two matrices element by element

Output Ready
Click Run to execute the example.

Requirements#

The matrices must have the same shape. You can’t add a \(2 \times 3\) matrix to a \(3 \times 2\) matrix.

Python Example

See why shape compatibility matters

Output Ready
Click Run to execute the example.

Scalar Multiplication (Scaling)#

You can also multiply a matrix by a single number (a scalar). This scales every element:

\[\begin{split} 3 \times \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} = \begin{bmatrix} 3 & 6 \\ 9 & 12 \end{bmatrix} \end{split}\]

In Python:

Python Example

Scale every element in a matrix

Output Ready
Click Run to execute the example.

Real-World Example#

Imagine you have sales data for two quarters:

Python Example

Combine quarterly sales data

Output Ready
Click Run to execute the example.

Properties#

Matrix addition has nice properties:

  • Commutative: \(A + B = B + A\)

  • Associative: \((A + B) + C = A + (B + C)\)

  • Identity: \(A + 0 = A\) (where \(0\) is a matrix of all zeros)

These work just like regular number addition.

Subtraction#

Matrix subtraction works the same way—subtract corresponding elements:

\[\begin{split} \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} - \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} = \begin{bmatrix} 4 & 4 \\ 4 & 4 \end{bmatrix} \end{split}\]

Python Example

Subtract corresponding entries

Output Ready
Click Run to execute the example.

Try It#

In the addition example, change one value in A and predict exactly which value in A + B will change.

Then try changing the scalar in the scaling example from 3 to -2. What happens to every entry?

Key Takeaways#

  • Matrix addition works element by element.

  • Matrix subtraction also works element by element.

  • Addition and subtraction require matching shapes.

  • Scalar multiplication scales every entry in the matrix.

Next Steps#

Addition is straightforward because it works element-by-element. But matrix Matrix Multiplication is different—and much more powerful. Let’s explore it next.