Thread

Article header

#Matrices

A matrix is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries. They are foundational element in many areas of #Mathematics and #Engineering including #Electronics #Computer #Science #Finances and more.

Notation and Terms

  • Dimensions: The size of a matrix is defined by its number of rows and columns and is often referred to as m x n, where m is the number of rows and n is the number of columns.
  • Square Matrix: A matrix with the same number of rows and columns (n x n).
  • Diagonal Matrix: A square matrix where all elements off the main diagonal are zero.
  • Identity Matrix: A diagonal matrix where all the elements on the main diagonal are 1. It's denoted as I.
  • Zero Matrix: A matrix all of whose entries are zero.

Basic Matrix Operations

  1. Addition and Subtraction
    • Matrices must be of the same dimensions to be added or subtracted.
    • Add or subtract corresponding elements.
    • Example:
    • $$\begin{bmatrix}1 & 2 \\3 & 4\end{bmatrix}+\begin{bmatrix}5 & 6 \\7 & 8\end{bmatrix}=\begin{bmatrix}6 & 8 \\10 & 12\end{bmatrix}$$
  2. Scalar Multiplication
  • Multiply every element of a matrix by a scalar (a single number).
  • Example:
  • $$ 2 \times \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} = \begin{bmatrix} 2 & 4 \\ 6 & 8 \end{bmatrix} $$
  1. Matrix Multiplication
  • The number of columns in the first matrix must be equal to the number of rows in the second matrix.
  • The product of an m x n matrix and an n x p matrix is an m x p matrix.
  • Multiply rows by columns, summing the products of the corresponding elements.
  • Example:
  • $$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \times \begin{bmatrix} 2 & 0 \\ 1 & 2 \end{bmatrix} = \begin{bmatrix} (1 \times 2 + 2 \times 1) & (1 \times 0 + 2 \times 2) \\ (3 \times 2 + 4 \times 1) & (3 \times 0 + 4 \times 2) \end{bmatrix} = \begin{bmatrix} 4 & 4 \\ 10 & 8 \end{bmatrix} $$

Special Matrix Operations

  1. Determinant
    • Only for square matrices.
    • A scalar value that can be computed from the elements of a square matrix and encodes certain properties of the matrix.
    • Example for a 2x2 matrix:
    • $$ \text{det} \begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc $$
  2. Inverse
    • Only for square matrices.
    • The matrix that, when multiplied by the original matrix, results in the identity matrix.
    • Not all matrices have inverses; a matrix must be "nonsingular" to have an inverse.

Practical Applications

  • Solving Systems of Linear Equations
    • Matrices are used to represent and solve systems of linear equations using methods like Gaussian elimination. $$X=A^{-1}\times B$$
  • Transformations in Computer Graphics
    • Matrix multiplication is used to perform geometric transformations such as rotations, translations, and scaling. $$R(\theta) = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{bmatrix}$$
Example System of Linear Equations

Suppose we have the following system of linear equations: $$3x + 4y = 5\\2x - y = 1$$ This system can be expressed as a matrix equation $AX=B$ where:

  • $A$ is the matrix of coefficients,
  • $X$ is the column matrix of variables,
  • $B$ is the column matrix of constants.
  • *Matrix A (coefficients): $$\begin{bmatrix} 3 & 4 \\ 2 & -1 \end{bmatrix}$$
  • *Matrix X (variables): $$\begin{bmatrix} x \\ y \end{bmatrix}$$
  • *Matrix B (constants): $$\begin{bmatrix} 5 \\ 1 \end{bmatrix}$$

Now Organising in Matrix form $$\begin{bmatrix} 3 & 4 \\ 2 & -1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 5 \\ 1 \end{bmatrix}$$

Solving the Equation

To solve for $X$, we can calculate the inverse of A (provided A is invertible) and then multiply it by B: $$X=A^{-1}\times B$$

Matrices with SymPy

from sympy import Matrix, symbols

# Define symbols
x, y, z = symbols('x y z')

# Define a 2x2 matrix
A = Matrix([[1, 2], [3, 4]])
print("Matrix A:")
print(A)

# Define a 3x3 matrix with symbolic elements
B = Matrix([[x, y, z], [y, z, x], [z, x, y]])
print("\nMatrix B:")
print(B)

# Define two matrices of the same size
C = Matrix([[5, 6], [7, 8]])
D = Matrix([[1, 1], [1, 1]])

# Addition
E = C + D
print("\nMatrix Addition (C + D):")
print(E)

# Subtraction
F = C - D
print("\nMatrix Subtraction (C - D):")
print(F)

# Scalar multiplication
G = 2 * A
print("\nScalar Multiplication (2 * A):")
print(G)

# Matrix multiplication
H = A * C
print("\nMatrix Multiplication (A * C):")
print(H)

# Determinant of a matrix
det_A = A.det()
print("\nDeterminant of Matrix A:")
print(det_A)

# Inverse of a matrix
inv_A = A.inv()
print("\nInverse of Matrix A:")
print(inv_A)

# Define the coefficient matrix A and the constant matrix B
A_sys = Matrix([[3, 4], [2, -1]])
B_sys = Matrix([5, 1])

# Solve the system AX = B
X = A_sys.inv() * B_sys
print("\nSolution to the system of linear equations:")
print(X)

# Compute eigenvalues and eigenvectors of a matrix
eigenvals = A.eigenvals()
eigenvects = A.eigenvects()

print("\nEigenvalues of Matrix A:")
print(eigenvals)

print("\nEigenvectors of Matrix A:")
print(eigenvects)

References

Replies (0)

No replies yet. Be the first to leave a comment!