Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Matrix Operations | Linear Algebra Foundations
Mathematics for Data Science

bookMatrix Operations

Note
Definition

A matrix is a rectangular array of numbers arranged in rows and columns, used to represent and solve mathematical problems efficiently.

Before jumping into linear systems, like Ax⃗=b⃗A\vec{x} = \vec{b}, it's essential to understand how matrices behave and what operations we can perform on them.

Matrix Addition

You can add two matrices only if they have the same shape (same number of rows and columns).

Let:

A=[a11a12a21a22],B=[b11b12b21b22]A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix}, \quad B = \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix}

Then:

A+B=[a11+b11a12+b12a21+b21a22+b22]A + B = \begin{bmatrix} a_{11} + b_{11} & a_{12} + b_{12} \\ a_{21} + b_{21} & a_{22} + b_{22} \end{bmatrix}

Scalar Multiplication

You can also multiply a matrix by a scalar (single number):

kβ‹…A=[ka11ka12ka21ka22]k \cdot A = \begin{bmatrix} k a_{11} & k a_{12} \\ k a_{21} & k a_{22} \end{bmatrix}

Matrix Multiplication and Size Compatibility

Matrix multiplication is a row-by-column operation, not element-wise.

Rule: if matrix AA is of shape (mΓ—n)(m \times n) and matrix BB is of shape (nΓ—p)(n \times p), then:

  • The multiplication ABAB is valid;
  • The result will be a matrix of shape (mΓ—p)(m \times p).

Example:

Let:

A=[1234],Β Β B=[56]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, \ \ B = \begin{bmatrix} 5 \\ 6 \end{bmatrix}

AA is (2Γ—2)(2 \times 2) and BB is (2Γ—1)(2 \times 1), then ABAB is valid and results in a (2Γ—1)(2 \times 1) matrix:

Aβ‹…B=[1β‹…5+2β‹…63β‹…5+4β‹…6]=[1739]A \cdot B = \begin{bmatrix} 1 \cdot 5 + 2 \cdot 6 \\ 3 \cdot 5 + 4 \cdot 6 \end{bmatrix} = \begin{bmatrix} 17 \\ 39 \end{bmatrix}

Transpose of a Matrix

The transpose of a matrix flips rows and columns. It is denoted as ATA^T.

Let:

A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}

Then:

AT=[1324]A^T = \begin{bmatrix} 1 & 3 \\ 2 & 4 \end{bmatrix}

Properties:

  • (AT)T=A(A^T)^T = A;
  • (A+B)T=AT+BT(A + B)^T = A^T + B^T;
  • (AB)T=BTAT(AB)^T = B^T A^T.

Determinant of a Matrix

2Γ—2 Matrix

For:

A=[abcd]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

The determinant is:

det⁑(A)=adβˆ’bc\det(A) = ad - bc

3Γ—3 Matrix

For:

A=[abcdefghi]A = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}

The determinant is:

det⁑(A)=a(eiβˆ’fh)βˆ’b(diβˆ’fg)+c(dhβˆ’eg)\det(A) = a(ei - fh) - b(di - fg) + c(dh - eg)

This method is called cofactor expansion.

  • Larger matrices (4Γ—4 and up) can be expanded recursively.
  • The determinant is useful because it indicates whether a matrix has an inverse (non-zero determinant).

Inverse of a Matrix

The inverse of a square matrix AA is denoted as Aβˆ’1A^{-1}. It satisfies Aβ‹…Aβˆ’1=IA \cdot A^{-1} = I, where II is the identity matrix.

Only square matrices with non-zero determinant have an inverse.

Example:

If matrix A is:

A=[abcd]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

Then its inverse matrix Aβˆ’1A^{-1} is:

Aβˆ’1=1det⁑(A)[dβˆ’bβˆ’ca]A^{-1} = \frac{1}{\det(A)} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}

Where det⁑(A)β‰ 0\det(A) \neq 0.

question mark

What is the transpose of [1234]\begin{bmatrix}1 & 2 \\3 & 4\end{bmatrix} matrix?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain why matrix multiplication is not element-wise?

How do you find the determinant of larger matrices?

What is the significance of the inverse of a matrix?

Awesome!

Completion rate improved to 1.96

bookMatrix Operations

Swipe to show menu

Note
Definition

A matrix is a rectangular array of numbers arranged in rows and columns, used to represent and solve mathematical problems efficiently.

Before jumping into linear systems, like Ax⃗=b⃗A\vec{x} = \vec{b}, it's essential to understand how matrices behave and what operations we can perform on them.

Matrix Addition

You can add two matrices only if they have the same shape (same number of rows and columns).

Let:

A=[a11a12a21a22],B=[b11b12b21b22]A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix}, \quad B = \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix}

Then:

A+B=[a11+b11a12+b12a21+b21a22+b22]A + B = \begin{bmatrix} a_{11} + b_{11} & a_{12} + b_{12} \\ a_{21} + b_{21} & a_{22} + b_{22} \end{bmatrix}

Scalar Multiplication

You can also multiply a matrix by a scalar (single number):

kβ‹…A=[ka11ka12ka21ka22]k \cdot A = \begin{bmatrix} k a_{11} & k a_{12} \\ k a_{21} & k a_{22} \end{bmatrix}

Matrix Multiplication and Size Compatibility

Matrix multiplication is a row-by-column operation, not element-wise.

Rule: if matrix AA is of shape (mΓ—n)(m \times n) and matrix BB is of shape (nΓ—p)(n \times p), then:

  • The multiplication ABAB is valid;
  • The result will be a matrix of shape (mΓ—p)(m \times p).

Example:

Let:

A=[1234],Β Β B=[56]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, \ \ B = \begin{bmatrix} 5 \\ 6 \end{bmatrix}

AA is (2Γ—2)(2 \times 2) and BB is (2Γ—1)(2 \times 1), then ABAB is valid and results in a (2Γ—1)(2 \times 1) matrix:

Aβ‹…B=[1β‹…5+2β‹…63β‹…5+4β‹…6]=[1739]A \cdot B = \begin{bmatrix} 1 \cdot 5 + 2 \cdot 6 \\ 3 \cdot 5 + 4 \cdot 6 \end{bmatrix} = \begin{bmatrix} 17 \\ 39 \end{bmatrix}

Transpose of a Matrix

The transpose of a matrix flips rows and columns. It is denoted as ATA^T.

Let:

A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}

Then:

AT=[1324]A^T = \begin{bmatrix} 1 & 3 \\ 2 & 4 \end{bmatrix}

Properties:

  • (AT)T=A(A^T)^T = A;
  • (A+B)T=AT+BT(A + B)^T = A^T + B^T;
  • (AB)T=BTAT(AB)^T = B^T A^T.

Determinant of a Matrix

2Γ—2 Matrix

For:

A=[abcd]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

The determinant is:

det⁑(A)=adβˆ’bc\det(A) = ad - bc

3Γ—3 Matrix

For:

A=[abcdefghi]A = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}

The determinant is:

det⁑(A)=a(eiβˆ’fh)βˆ’b(diβˆ’fg)+c(dhβˆ’eg)\det(A) = a(ei - fh) - b(di - fg) + c(dh - eg)

This method is called cofactor expansion.

  • Larger matrices (4Γ—4 and up) can be expanded recursively.
  • The determinant is useful because it indicates whether a matrix has an inverse (non-zero determinant).

Inverse of a Matrix

The inverse of a square matrix AA is denoted as Aβˆ’1A^{-1}. It satisfies Aβ‹…Aβˆ’1=IA \cdot A^{-1} = I, where II is the identity matrix.

Only square matrices with non-zero determinant have an inverse.

Example:

If matrix A is:

A=[abcd]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

Then its inverse matrix Aβˆ’1A^{-1} is:

Aβˆ’1=1det⁑(A)[dβˆ’bβˆ’ca]A^{-1} = \frac{1}{\det(A)} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}

Where det⁑(A)β‰ 0\det(A) \neq 0.

question mark

What is the transpose of [1234]\begin{bmatrix}1 & 2 \\3 & 4\end{bmatrix} matrix?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3
some-alt