

# Matrix addition and subtraction

Matrix addition and subtraction are fundamental operations in linear algebra. They involve adding or subtracting corresponding elements of two matrices.

To add two matrices, the matrices must have the same dimensions. For example, if we have two 2x2 matrices A and B, we can add them as follows:

$$
A = \begin{bmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
b_{11} & b_{12} \\
b_{21} & b_{22} \\
\end{bmatrix}
$$

The sum of A and B is:

$$
A + B = \begin{bmatrix}
a_{11} + b_{11} & a_{12} + b_{12} \\
a_{21} + b_{21} & a_{22} + b_{22} \\
\end{bmatrix}
$$

Similarly, to subtract two matrices, the matrices must also have the same dimensions. For example, if we have two 2x2 matrices A and B, we can subtract them as follows:

$$
A = \begin{bmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
b_{11} & b_{12} \\
b_{21} & b_{22} \\
\end{bmatrix}
$$

The difference of A and B is:

$$
A - B = \begin{bmatrix}
a_{11} - b_{11} & a_{12} - b_{12} \\
a_{21} - b_{21} & a_{22} - b_{22} \\
\end{bmatrix}
$$

## Exercise
Calculate the sum and difference of the following matrices:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
5 & 6 \\
7 & 8 \\
\end{bmatrix}
$$

# Hadamard product

The Hadamard product, also known as the element-wise product or Schur product, is a binary operation that takes two matrices of the same size and returns a matrix where each element is the product of the corresponding elements in the input matrices.

To find the Hadamard product of two matrices, simply multiply the corresponding elements in the matrices. For example, if we have two 2x2 matrices A and B, we can find their Hadamard product as follows:

$$
A = \begin{bmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
b_{11} & b_{12} \\
b_{21} & b_{22} \\
\end{bmatrix}
$$

The Hadamard product of A and B is:

$$
A \circ B = \begin{bmatrix}
a_{11} \cdot b_{11} & a_{12} \cdot b_{12} \\
a_{21} \cdot b_{21} & a_{22} \cdot b_{22} \\
\end{bmatrix}
$$

## Exercise
Find the Hadamard product of the following matrices:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
5 & 6 \\
7 & 8 \\
\end{bmatrix}
$$

# Matrix multiplication basics

Matrix multiplication is a binary operation that takes two matrices and returns a matrix. The number of columns in the first matrix must be equal to the number of rows in the second matrix.

To multiply two matrices, we follow these steps:

1. Transpose the second matrix.
2. Multiply the transposed matrix by the first matrix element-wise.
3. Transpose the result back.

For example, if we have two matrices A and B, we can find their product as follows:

$$
A = \begin{bmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
b_{11} & b_{12} \\
b_{21} & b_{22} \\
\end{bmatrix}
$$

The product of A and B is:

$$
AB = \begin{bmatrix}
a_{11} \cdot b_{11} + a_{12} \cdot b_{21} & a_{11} \cdot b_{12} + a_{12} \cdot b_{22} \\
a_{21} \cdot b_{11} + a_{22} \cdot b_{21} & a_{21} \cdot b_{12} + a_{22} \cdot b_{22} \\
\end{bmatrix}
$$

## Exercise
Find the product of the following matrices:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
5 & 6 \\
7 & 8 \\
\end{bmatrix}
$$

# Matrix transpose

The transpose of a matrix is obtained by flipping the matrix over its main diagonal. The transpose of a matrix A is denoted as A^T.

To find the transpose of a matrix, swap its rows and columns. For example, if we have a 2x3 matrix A, its transpose is:

$$
A = \begin{bmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
\end{bmatrix}
$$

The transpose of A is:

$$
A^T = \begin{bmatrix}
a_{11} & a_{21} \\
a_{12} & a_{22} \\
a_{13} & a_{23} \\
\end{bmatrix}
$$

## Exercise
Find the transpose of the following matrix:

$$
A = \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{bmatrix}
$$

# Matrix inversion

Matrix inversion is the process of finding the inverse of a matrix. The inverse of a matrix A is denoted as A^(-1).

To find the inverse of a matrix, we need to solve the linear system:

$$
AA^(-1) = I
$$

Where I is the identity matrix of the same size as A.

There are several methods to find the inverse of a matrix, such as Gaussian elimination, adjugate matrix, and determinant.

## Exercise
Find the inverse of the following matrix:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix}
$$

# Properties of matrix operations

Matrix operations have several properties that can be used to simplify calculations and solve problems more efficiently. Some of these properties include:

- Commutative property: Matrix addition and subtraction are commutative operations, meaning the order in which the matrices are added or subtracted does not affect the result.

- Associative property: Matrix addition and subtraction are associative operations, meaning that the order in which the operations are performed does not affect the result.

- Distributive property: Matrix multiplication distributes over matrix addition and subtraction.

- Identity property: The identity matrix acts as the multiplicative identity for matrix multiplication.

- Inverse property: If a matrix A has an inverse, then A * A^(-1) = I and A^(-1) * A = I.

## Exercise
Verify the commutative and associative properties for matrix addition and subtraction using the following matrices:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix} \text{ and }
B = \begin{bmatrix}
5 & 6 \\
7 & 8 \\
\end{bmatrix}
$$

# Identity matrix and its uses

The identity matrix is a square matrix with ones on the diagonal and zeros elsewhere. The identity matrix is denoted as I and has the following properties:

- It acts as the multiplicative identity for matrix multiplication.

- It acts as the additive identity for matrix addition.

- It is the only matrix that satisfies the equation A * A^(-1) = I.

The identity matrix is used in various applications, such as:

- Initializing variables in algorithms.
- Representing the absence of a transformation in graphics.
- Diagonalizing a matrix using the eigendecomposition.

## Exercise
Find the identity matrix of size 3x3.

# Cofactor and determinant

The cofactor of an element in a matrix is the product of its corresponding cofactor and the element itself. The determinant of a matrix is the product of the diagonal elements of its LU decomposition.

To find the cofactor and determinant of a matrix, we can use the following steps:

1. Calculate the LU decomposition of the matrix.
2. Calculate the product of the diagonal elements in the LU decomposition.
3. The cofactor of an element is the product of its corresponding cofactor and the element itself.

## Exercise
Find the cofactor and determinant of the following matrix:

$$
A = \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{bmatrix}
$$

# Matrix inversion using determinant

The inverse of a matrix can be found using the determinant method. The inverse of a matrix A is denoted as A^(-1).

To find the inverse of a matrix using the determinant method, we need to solve the linear system:

$$
AA^(-1) = I
$$

Where I is the identity matrix of the same size as A.

## Exercise
Find the inverse of the following matrix using the determinant method:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix}
$$

# Matrix inversion using adjugate

The inverse of a matrix can also be found using the adjugate method. The inverse of a matrix A is denoted as A^(-1).

To find the inverse of a matrix using the adjugate method, we need to solve the linear system:

$$
AA^(-1) = I
$$

Where I is the identity matrix of the same size as A.

## Exercise
Find the inverse of the following matrix using the adjugate method:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix}
$$

# Matrix inverse and its properties

The inverse of a matrix is a matrix that, when multiplied by the original matrix, results in the identity matrix. The inverse of a matrix A is denoted as A^(-1).

Some properties of the inverse of a matrix include:

- The inverse of a matrix A is unique if it exists.

- The inverse of a matrix A is equal to the reciprocal of its determinant.

- The inverse of the inverse of a matrix A is equal to the original matrix A.

## Exercise
Find the inverse of the following matrix and verify its properties:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix}
$$

# Matrix multiplication and vector multiplication

Matrix multiplication is not the same as vector multiplication. When multiplying a matrix by a vector, the vector is treated as a column matrix and the result is a column matrix.

To multiply a matrix by a vector, we multiply the matrix by the vector as if it were a column matrix. For example, if we have a 2x2 matrix A and a 2x1 vector x, we can find their product as follows:

$$
A = \begin{bmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} \\
\end{bmatrix} \text{ and }
x = \begin{bmatrix}
x_1 \\
x_2 \\
\end{bmatrix}
$$

The product of A and x is:

$$
Ax = \begin{bmatrix}
a_{11} \cdot x_1 + a_{12} \cdot x_2 \\
a_{21} \cdot x_1 + a_{22} \cdot x_2 \\
\end{bmatrix}
$$

## Exercise
Multiply the following matrix by the vector:

$$
A = \begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix} \text{ and }
x = \begin{bmatrix}
5 \\
6 \\
\end{bmatrix}
$$

# Applications of matrix multiplication techniques

Matrix multiplication techniques are used in various applications, such as:

- Linear systems and equations.

- Eigendecomposition and diagonalization of matrices.

- Image processing and computer vision.

- Machine learning and data analysis.

- Control theory and signal processing.

## Exercise
Apply matrix multiplication techniques to solve the following problem:

Given a matrix A and a vector x, find a vector y such that A * y = x.