Chapter 5: Matrices
Section 5.7 Matrices
Matrices Operation
TerminologyData about many kinds of problems can often be represented using a rectangular arrangement of values; such an arrangement is called a matrix . Thus:
Elements of a matrix A are denoted by \( a_{ij} \), where \(i\) is the row number of the element in the matrix and \(j\) is the column number. In the example matrix A, \(a_{23} = 8\) because 8 is the element in row 2, column 3, of A.
Example 1:
Average temperatures in three different cities for each month can be neatly summarized in a \( 3 \times 12\) matrix. Here we interpret the 3 rows as the 3 cities and the 12 columns as the 12 months Januray-December. The average temperature in the third city in April, \(a_{34}\),is 67.
Square Matrices
We will often be interested in square matrices, in which the number of rows equals the number of columns . If A is an \(n \times n\) square matrix, then the elements \( a_{11}, a_{22}, \dots, a_{nn}\) form the main diagonal of the matrix.Symmetric Matrix
A symmetric matrix is a square matrix that is equal to its transpose. In a symmetric matrix, \( a_{ij} = a_{ji} \).Identity Matrix
The identity matrix of size \(n\) is the \(n \times n\) square matrix with ones on the main diagonal and zeros elsewhere. It is denoted by I. If we multiply I times any \(n \times n\) matrix A, we get A as the result. The identity matrix behaves similarly to the number 1 in regular arithmetic. The equation: $$ I·A = A·I = A$$Applications of Identity Matrix
- An identity matrix is used to find the inverse of a matrix.
- An identity matrix is used to find the eigenvalues and eigenvectors.
Matrix Inverse
An \(n \times n\) matrix A is invertible if there exists an \(n \times n\) matrix B such that$$A·B = B·A = I$$ In this case, B is called the inverse of A, denoted by \(A^{-1}\).
Applications of Inverse Matrix
- An inverse matrix is used to solve a system of linear equations.
- Helps in computing eigenvalues and eigenvectors.
Matrix Operations
We can define arithmetic operations on matrices whose entries are numerical. These operations make matrices interesting objects to study in their own right, but they also make matrices more useful for certain tasks such as solving systems of equations.Scalar Multiplication
Scalar multiplication , calls for multiplying each entry of a matrix by a fixed single number called a scalar. The result is a matrix with the same dimensions as the orginial matrix.Matrix Addition
Addition of two matrices A and B is defined only when A and B have the same dimensions; then it is simply a mater of adding the corresponding elements. Formally, if A and B are both \( n \times m \) matrices, then C = A + B is an \( n \times m\) matrix with entries: \( c_{ij} = a_{ij} + b_{ij}\).Matrix Subtraction
Subtraction of matrices is defined by \(A - B = A + (-1)B\).Matrix Multiplication
To compute A times B, \(A · B\), the number of columns in A must equal the number of rows in B. Thus we can compute \(A·B\) if A is an \(n \times m\) matrix and B is an \(m \times p\) matrix. The result is an \( n \times p\) matrix. An entry in row \(i\), column \(j\) of \(A · B\) is obtained by multiplying all the elements in row \(i\) of A by the corresponding elements in column \(j\) of B and adding the results. Formally, \(A · B = C\), where \( c_{ij} = \sum\limits_{k=1}^ma_{ik}b_{kj}\)The complete product is:
Matrix multiplication pseudocode
It is easy to write an algorithm for matrix multiplication by simply following the definition. A pseudocode version of the algorithm follows, where bracket notation \(A[i,j]\) replaces the subscript notation \(a_{ij}\).Algorithm Matrix multiplication
//computes \(n \times p\) matrix \(A · B\) for \(n \times m\) matrix \(A\), \(m \times p\) matrix \(B\)
//stores result in C
for i = 1 to n do
for j = 1 to p do
C[i,j] = 0
for k = 1 to m do
C[i,j] = C[i,j] + A[i,k]*B[k,j]
end for
end for
end for
write out product matrix C
matrix2DArray.cpp
matrix2DVector.cpp
Time Complexity Analysis
Since we have three nested loops, each iterating up to \(n\), \(p\), and \(m\), the total operations are: \( O(n \times p \times m) \)Tautologies 1
If A and B are \(n \times m\) matrices and \(r\) and \(s\) are scalars, the following matrix equations are true:\( 1. \quad 0 + A = A \\ 2. \quad A + B = B + A \\ 3. \quad (A+B)+C = A+(B+C) \\ 4. \quad r(A+B) = rA + rB \\ 5. \quad (r+s)A = rA + sA \\ 6. \quad r(sA) = (rs)A \\ \)
Tautologies 2
Where A,B, and C are matrices of appropriate dimensions and \(r\) and \(s\) are scalars, the following matrix equations are true:\( A·(B·C) = (A·B)·C \\ A(B+C) = A·B + A·C \\ (A+B)C = A·C + B·C \\ rA·sB = (rs)(A·B) \\ \)
Practice
(1) For \(r=2\), find \(rA+B\).(2) Compute \(A·B\) and \(B·A\) for
Applications of Matrices
- Computer Graphics: Matrices are used for 3D transformations and image processing.
- Machine Learning & AI: Matrices are widely used in neural networks, data representation, and statistical modeling.
- Physics & Engineering: Matrices help in vector transformations and simulating systems.
Reference
saylor academyInverse Matrix