math-matrix-operation.html


* created: 2025-06-02T23:16
* modified: 2025-09-20T15:41

title

Matrix operation

description

You can do math with the matrix.

Arithmetic with matrices

Multiplying matrices

Multiplying matrices is only possible if the one matrix has as many columns as the second matrix has rows.

We multiply each element of each row of the first matrix by the corresponding element of each column of the second matrix, then sum these products.

We define:

A := \begin{bmatrix} 1 & -1 & 2 \\ -2 & 0 & 6 \end{bmatrix} , \; B := \begin{bmatrix} 1 & -2 \\ 4 & 5 \\ -3 & 7 \end{bmatrix} \; \text{and} \; C := \begin{bmatrix} 9 \\ 4 \\ 7 \end{bmatrix}

To calculate A \cdot B:

$$ X = \begin{bmatrix} 1 \cdot 1 + -1 \cdot 4 + 2 \cdot -3 & 1 \cdot -2 + -1 \cdot 5 + 2 \cdot 7 \ -2 \cdot 1 + 0 \cdot 4 + 6 \cdot -3 & -2 \cdot -2 + 0 \cdot 5 + 6 \cdot 7 \end{bmatrix}

\begin{bmatrix} -9 & 7 \ -20 & 46 \end{bmatrix} $$

The resulting matrix has 2\times2 dimensions.

To calculate B \cdot A:

$$ X = \begin{bmatrix} 1 \cdot 1 + -2 \cdot -2 & 1 \cdot -1 + -2 \cdot 0 & 1 \cdot 2 + -2 \cdot 6 \ 4 \cdot 1 + 5 \cdot -2 & 4 \cdot -1 + 5 \cdot 0 & 4 \cdot 2 + 5 \cdot 6 \ -3 \cdot 1 + 7 \cdot -2 & -3 \cdot -1 + 0 \cdot 7 & -3 \cdot 2 + 7 \cdot 6 \ \end{bmatrix}

\begin{bmatrix} 5 & -1 & -10 \ -6 & -4 & 38 \ -17 & 3 & 36 \end{bmatrix} $$

The resulting matrix has 3 \times 3 dimensions.