Skip to main content

Matrices — Diagnostic Tests

Unit Tests

UT-1: Matrix Operations and Inverses

Question: Given A=(3124)\mathbf{A} = \begin{pmatrix} 3 & 1 \\ 2 & 4 \end{pmatrix} and B=(1102)\mathbf{B} = \begin{pmatrix} 1 & -1 \\ 0 & 2 \end{pmatrix}, (a) calculate AB\mathbf{AB} and BA\mathbf{BA}. Is matrix multiplication commutative? (b) Calculate det(A)\det(\mathbf{A}) and A1\mathbf{A}^{-1}. (c) Solve Ax=(712)\mathbf{A}\mathbf{x} = \begin{pmatrix} 7 \\ 12 \end{pmatrix}. (d) Calculate (AB)1(\mathbf{AB})^{-1} and verify it equals B1A1\mathbf{B}^{-1}\mathbf{A}^{-1}.

Solution:

(a) AB=(3124)(1102)=(3126)\mathbf{AB} = \begin{pmatrix} 3 & 1 \\ 2 & 4 \end{pmatrix}\begin{pmatrix} 1 & -1 \\ 0 & 2 \end{pmatrix} = \begin{pmatrix} 3 & -1 \\ 2 & 6 \end{pmatrix}. BA=(1102)(3124)=(1348)\mathbf{BA} = \begin{pmatrix} 1 & -1 \\ 0 & 2 \end{pmatrix}\begin{pmatrix} 3 & 1 \\ 2 & 4 \end{pmatrix} = \begin{pmatrix} 1 & -3 \\ 4 & 8 \end{pmatrix}. ABBA\mathbf{AB} \ne \mathbf{BA}, so matrix multiplication is not commutative.

(b) det(A)=3(4)1(2)=122=10\det(\mathbf{A}) = 3(4) - 1(2) = 12 - 2 = 10. A1=110(4123)=(0.40.10.20.3)\mathbf{A}^{-1} = \frac{1}{10}\begin{pmatrix} 4 & -1 \\ -2 & 3 \end{pmatrix} = \begin{pmatrix} 0.4 & -0.1 \\ -0.2 & 0.3 \end{pmatrix}.

(c) x=A1(712)=(0.40.10.20.3)(712)=(2.81.21.4+3.6)=(1.62.2)\mathbf{x} = \mathbf{A}^{-1}\begin{pmatrix} 7 \\ 12 \end{pmatrix} = \begin{pmatrix} 0.4 & -0.1 \\ -0.2 & 0.3 \end{pmatrix}\begin{pmatrix} 7 \\ 12 \end{pmatrix} = \begin{pmatrix} 2.8 - 1.2 \\ -1.4 + 3.6 \end{pmatrix} = \begin{pmatrix} 1.6 \\ 2.2 \end{pmatrix}.

(d) det(B)=1(2)(1)(0)=2\det(\mathbf{B}) = 1(2) - (-1)(0) = 2. B1=12(2101)\mathbf{B}^{-1} = \frac{1}{2}\begin{pmatrix} 2 & 1 \\ 0 & 1 \end{pmatrix}. B1A1=120(2101)(4123)=120(6123)\mathbf{B}^{-1}\mathbf{A}^{-1} = \frac{1}{20}\begin{pmatrix} 2 & 1 \\ 0 & 1 \end{pmatrix}\begin{pmatrix} 4 & -1 \\ -2 & 3 \end{pmatrix} = \frac{1}{20}\begin{pmatrix} 6 & 1 \\ -2 & 3 \end{pmatrix}.

(AB)1(\mathbf{AB})^{-1}: det(AB)=3(6)(1)(2)=20\det(\mathbf{AB}) = 3(6) - (-1)(2) = 20. (AB)1=120(6123)(\mathbf{AB})^{-1} = \frac{1}{20}\begin{pmatrix} 6 & 1 \\ -2 & 3 \end{pmatrix}. Confirmed equal.

UT-2: 3x3 Determinants and Inverses

Question: M=(120013201)\mathbf{M} = \begin{pmatrix} 1 & 2 & 0 \\ 0 & 1 & 3 \\ 2 & 0 & 1 \end{pmatrix}. (a) Calculate det(M)\det(\mathbf{M}). (b) Find M1\mathbf{M}^{-1}. (c) Solve Mx=(574)\mathbf{M}\mathbf{x} = \begin{pmatrix} 5 \\ 7 \\ 4 \end{pmatrix}. (d) Explain what det(M)=0\det(\mathbf{M}) = 0 would mean.

Solution:

(a) det(M)=1130120321+0=1(10)2(06)=1+12=13\det(\mathbf{M}) = 1\begin{vmatrix} 1 & 3 \\ 0 & 1 \end{vmatrix} - 2\begin{vmatrix} 0 & 3 \\ 2 & 1 \end{vmatrix} + 0 = 1(1 - 0) - 2(0 - 6) = 1 + 12 = 13.

(b) Cofactors: C11=1C_{11} = 1, C12=6C_{12} = 6, C13=2C_{13} = -2, C21=2C_{21} = -2, C22=1C_{22} = 1, C23=4C_{23} = 4, C31=6C_{31} = 6, C32=3C_{32} = -3, C33=1C_{33} = 1.

M1=113(126613241)\mathbf{M}^{-1} = \frac{1}{13}\begin{pmatrix} 1 & -2 & 6 \\ 6 & 1 & -3 \\ -2 & 4 & 1 \end{pmatrix}.

(c) x=M1(574)=113(514+2430+71210+28+4)=113(152522)\mathbf{x} = \mathbf{M}^{-1}\begin{pmatrix} 5 \\ 7 \\ 4 \end{pmatrix} = \frac{1}{13}\begin{pmatrix} 5 - 14 + 24 \\ 30 + 7 - 12 \\ -10 + 28 + 4 \end{pmatrix} = \frac{1}{13}\begin{pmatrix} 15 \\ 25 \\ 22 \end{pmatrix}.

(d) If det(M)=0\det(\mathbf{M}) = 0, the matrix is singular (non-invertible). This means: the rows (and columns) are linearly dependent, the matrix does not have full rank, the system Mx=b\mathbf{M}\mathbf{x} = \mathbf{b} has either no solution or infinitely many solutions (depending on b\mathbf{b}), and the corresponding linear transformation collapses the space into a lower dimension.

UT-3: Eigenvalues and Eigenvectors

Question: A=(4123)\mathbf{A} = \begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix}. (a) Find the eigenvalues of A\mathbf{A}. (b) Find the corresponding eigenvectors. (c) Form the matrix P\mathbf{P} of eigenvectors and P1AP\mathbf{P}^{-1}\mathbf{A}\mathbf{P}. What form does this take? (d) Use the eigenvalues to calculate A5\mathbf{A}^5.

Solution:

(a) det(AλI)=4λ123λ=(4λ)(3λ)2=λ27λ+10=0\det(\mathbf{A} - \lambda\mathbf{I}) = \begin{vmatrix} 4-\lambda & 1 \\ 2 & 3-\lambda \end{vmatrix} = (4-\lambda)(3-\lambda) - 2 = \lambda^2 - 7\lambda + 10 = 0. (λ5)(λ2)=0(\lambda - 5)(\lambda - 2) = 0. Eigenvalues: λ1=5\lambda_1 = 5, λ2=2\lambda_2 = 2.

(b) For λ=5\lambda = 5: (A5I)v=0(\mathbf{A} - 5\mathbf{I})\mathbf{v} = \mathbf{0}. (1122)(xy)=0\begin{pmatrix} -1 & 1 \\ 2 & -2 \end{pmatrix}\begin{pmatrix} x \\ y \end{pmatrix} = \mathbf{0}. x+y=0-x + y = 0, y=xy = x. Eigenvector: (11)\begin{pmatrix} 1 \\ 1 \end{pmatrix}.

For λ=2\lambda = 2: (A2I)v=0(\mathbf{A} - 2\mathbf{I})\mathbf{v} = \mathbf{0}. (2121)(xy)=0\begin{pmatrix} 2 & 1 \\ 2 & 1 \end{pmatrix}\begin{pmatrix} x \\ y \end{pmatrix} = \mathbf{0}. 2x+y=02x + y = 0, y=2xy = -2x. Eigenvector: (12)\begin{pmatrix} 1 \\ -2 \end{pmatrix}.

(c) P=(1112)\mathbf{P} = \begin{pmatrix} 1 & 1 \\ 1 & -2 \end{pmatrix}. det(P)=3\det(\mathbf{P}) = -3. P1=13(2111)=13(2111)\mathbf{P}^{-1} = \frac{1}{-3}\begin{pmatrix} -2 & -1 \\ -1 & 1 \end{pmatrix} = \frac{1}{3}\begin{pmatrix} 2 & 1 \\ 1 & -1 \end{pmatrix}.

D=P1AP=(5002)\mathbf{D} = \mathbf{P}^{-1}\mathbf{A}\mathbf{P} = \begin{pmatrix} 5 & 0 \\ 0 & 2 \end{pmatrix} (diagonal matrix of eigenvalues).

(d) A5=PD5P1=(1112)(31250032)13(2111)\mathbf{A}^5 = \mathbf{P}\mathbf{D}^5\mathbf{P}^{-1} = \begin{pmatrix} 1 & 1 \\ 1 & -2 \end{pmatrix}\begin{pmatrix} 3125 & 0 \\ 0 & 32 \end{pmatrix}\frac{1}{3}\begin{pmatrix} 2 & 1 \\ 1 & -1 \end{pmatrix}.

=13(312532312564)(2111)=13(6282309361863189)=(2094103120621063)= \frac{1}{3}\begin{pmatrix} 3125 & 32 \\ 3125 & -64 \end{pmatrix}\begin{pmatrix} 2 & 1 \\ 1 & -1 \end{pmatrix} = \frac{1}{3}\begin{pmatrix} 6282 & 3093 \\ 6186 & 3189 \end{pmatrix} = \begin{pmatrix} 2094 & 1031 \\ 2062 & 1063 \end{pmatrix}.


Integration Tests

IT-1: Matrices and Geometric Transformations (with Vectors)

Question: The matrix T=(0110)\mathbf{T} = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} represents a rotation. (a) Find the angle and direction of rotation. (b) The point (3,4)(3, 4) is transformed by T\mathbf{T}. Calculate the image. (c) If S=(1001)\mathbf{S} = \begin{pmatrix} -1 & 0 \\ 0 & 1 \end{pmatrix} (reflection in the yy-axis), find TS\mathbf{TS} and describe the combined transformation. (d) Calculate det(T)\det(\mathbf{T}) and det(S)\det(\mathbf{S}), and explain how determinants relate to area scale factors.

Solution:

(a) T\mathbf{T} maps (1,0)(1, 0) to (0,1)(0, 1) and (0,1)(0, 1) to (1,0)(-1, 0). This is a rotation of 9090^\circ anticlockwise about the origin.

(b) (0110)(34)=(43)\begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 3 \\ 4 \end{pmatrix} = \begin{pmatrix} -4 \\ 3 \end{pmatrix}. Image: (4,3)(-4, 3).

(c) TS=(0110)(1001)=(0110)\mathbf{TS} = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} -1 & 0 \\ 0 & 1 \end{pmatrix} = \begin{pmatrix} 0 & -1 \\ -1 & 0 \end{pmatrix}.

This maps (1,0)(1,0) to (0,1)(0,-1) and (0,1)(0,1) to (1,0)(-1,0): a reflection in the line y=xy = -x.

(d) det(T)=0×0(1)×1=1\det(\mathbf{T}) = 0 \times 0 - (-1) \times 1 = 1. det(S)=1×10=1\det(\mathbf{S}) = -1 \times 1 - 0 = -1.

The absolute value of the determinant gives the area scale factor: T\mathbf{T} preserves area (scale factor 1), S\mathbf{S} preserves area (scale factor 1=1|-1| = 1). The sign indicates orientation: positive == orientation preserved (rotation), negative == orientation reversed (reflection).

IT-2: Systems of Linear Equations (with Complex Numbers)

Question: Solve the system: x+2y+z=4x + 2y + z = 4, 2xy+3z=92x - y + 3z = 9, x+y+z=5x + y + z = 5. (a) Write in matrix form Ax=b\mathbf{A}\mathbf{x} = \mathbf{b}. (b) Calculate det(A)\det(\mathbf{A}). (c) Find A1\mathbf{A}^{-1} and solve for x\mathbf{x}. (d) Explain what would happen if det(A)=0\det(\mathbf{A}) = 0.

Solution:

(a) (121213111)(xyz)=(495)\begin{pmatrix} 1 & 2 & 1 \\ 2 & -1 & 3 \\ 1 & 1 & 1 \end{pmatrix}\begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} 4 \\ 9 \\ 5 \end{pmatrix}.

(b) det(A)=1(13)2(23)+1(2+1)=4+2+3=1\det(\mathbf{A}) = 1(-1 - 3) - 2(2 - 3) + 1(2 + 1) = -4 + 2 + 3 = 1.

(c) Cofactors: C11=4C_{11} = -4, C12=1C_{12} = 1, C13=3C_{13} = 3, C21=1C_{21} = -1, C22=0C_{22} = 0, C23=1C_{23} = 1, C31=7C_{31} = 7, C32=1C_{32} = -1, C33=5C_{33} = -5.

A1=(417101315)\mathbf{A}^{-1} = \begin{pmatrix} -4 & -1 & 7 \\ 1 & 0 & -1 \\ 3 & 1 & -5 \end{pmatrix}.

x=A1(495)=(169+354+0512+925)=(1014)\mathbf{x} = \mathbf{A}^{-1}\begin{pmatrix} 4 \\ 9 \\ 5 \end{pmatrix} = \begin{pmatrix} -16 - 9 + 35 \\ 4 + 0 - 5 \\ 12 + 9 - 25 \end{pmatrix} = \begin{pmatrix} 10 \\ -1 \\ -4 \end{pmatrix}.

x=10x = 10, y=1y = -1, z=4z = -4. Verification: 1024=410 - 2 - 4 = 4 \checkmark; 20+112=920 + 1 - 12 = 9 \checkmark; 1014=510 - 1 - 4 = 5 \checkmark.

(d) If det(A)=0\det(\mathbf{A}) = 0, the matrix is singular and A1\mathbf{A}^{-1} does not exist. This means the three equations are linearly dependent. The system has either no unique solution: either no solution (inconsistent) or infinitely many solutions.

IT-3: Matrix Applications (with Differential Equations)

Question: The matrix A=(2112)\mathbf{A} = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} defines a system of coupled differential equations LBdxRB◆◆LBdtRB=Ax\frac◆LB◆d\mathbf{x}◆RB◆◆LB◆dt◆RB◆ = \mathbf{A}\mathbf{x} where x=(xy)\mathbf{x} = \begin{pmatrix} x \\ y \end{pmatrix}. (a) Find the eigenvalues and eigenvectors of A\mathbf{A}. (b) Write the general solution for x(t)\mathbf{x}(t) given that x(0)=(31)\mathbf{x}(0) = \begin{pmatrix} 3 \\ 1 \end{pmatrix}. (c) Calculate x(1)\mathbf{x}(1). (d) Describe the long-term behaviour of the solution.

Solution:

(a) det(AλI)=(2λ)21=λ24λ+3=0\det(\mathbf{A} - \lambda\mathbf{I}) = (2-\lambda)^2 - 1 = \lambda^2 - 4\lambda + 3 = 0. λ1=3\lambda_1 = 3, λ2=1\lambda_2 = 1.

λ=3\lambda = 3: eigenvector (11)\begin{pmatrix} 1 \\ 1 \end{pmatrix}. λ=1\lambda = 1: eigenvector (11)\begin{pmatrix} 1 \\ -1 \end{pmatrix}.

(b) General solution: x(t)=c1e3t(11)+c2et(11)\mathbf{x}(t) = c_1 e^{3t}\begin{pmatrix} 1 \\ 1 \end{pmatrix} + c_2 e^{t}\begin{pmatrix} 1 \\ -1 \end{pmatrix}.

x(0)=c1(11)+c2(11)=(31)\mathbf{x}(0) = c_1\begin{pmatrix} 1 \\ 1 \end{pmatrix} + c_2\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 3 \\ 1 \end{pmatrix}. c1+c2=3c_1 + c_2 = 3 and c1c2=1c_1 - c_2 = 1. Solving: c1=2c_1 = 2, c2=1c_2 = 1.

x(t)=2e3t(11)+et(11)=(2e3t+et2e3tet)\mathbf{x}(t) = 2e^{3t}\begin{pmatrix} 1 \\ 1 \end{pmatrix} + e^{t}\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 2e^{3t} + e^t \\ 2e^{3t} - e^t \end{pmatrix}.

(c) x(1)=(2e3+e2e3e)=(2(20.086)+2.7182(20.086)2.718)=(42.8937.45)\mathbf{x}(1) = \begin{pmatrix} 2e^3 + e \\ 2e^3 - e \end{pmatrix} = \begin{pmatrix} 2(20.086) + 2.718 \\ 2(20.086) - 2.718 \end{pmatrix} = \begin{pmatrix} 42.89 \\ 37.45 \end{pmatrix}.

(d) As tt \to \infty, the term e3te^{3t} dominates (both eigenvalues are positive). Both xx and yy grow exponentially, with x2e3tx \approx 2e^{3t} and y2e3ty \approx 2e^{3t}. The solution diverges away from the origin -- the origin is an unstable node. The ratio x/y1x/y \to 1 as tt \to \infty, meaning the trajectory approaches the direction of the eigenvector (11)\begin{pmatrix} 1 \\ 1 \end{pmatrix}.