Differential Equations for EngineersXYZ Homework Edition

⇩ Download ▾

3.2 Matrices and linear systems

Matrices and vectors

Before we can start talking about linear systems of ODEs, we will need to talk about matrices, so let us review these briefly. A matrix is an m×nm \times n array of numbers (mm rows and nn columns). For example, we denote a 3×53 \times 5 matrix as follows

A = [ a 11 a 12 a 13 a 14 a 15 a 21 a 22 a 23 a 24 a 25 a 31 a 32 a 33 a 34 a 35 ] A = \begin {bmatrix} a_{11} & a_{12} & a_{13} & a_{14} & a_{15} \\ a_{21} & a_{22} & a_{23} & a_{24} & a_{25} \\ a_{31} & a_{32} & a_{33} & a_{34} & a_{35} \end {bmatrix} \nonumber

The numbers aija_{ij} are called elements or entries.

By a vector we will usually mean a column vector, that is an m×1m \times 1 matrix. If we mean a row vector we will explicitly say so (a row vector is a 1×n1 \times n matrix). We will usually denote matrices by upper case letters and vectors by lower case letters with an arrow such as x\vec {\text {x}} or b\vec {b}. By 0\vec {0} we will mean the vector of all zeros.

It is easy to define some operations on matrices. Note that we will want 1×11 \times 1 matrices to really act like numbers, so our operations will have to be compatible with this viewpoint.

First, we can multiply by a scalar (a number). This means just multiplying each entry by the same number. For example,

2 [ 1 2 3 4 5 6 ] = [ 2 4 6 8 10 12 ] 2 {\begin {bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end {bmatrix}} = \begin {bmatrix} 2 & 4 & 6 \\ 8 & 10 & 12 \end {bmatrix} \nonumber

Matrix addition is also easy. We add matrices element by element. For example,

[ 1 2 3 4 5 6 ] + [ 1 1 1 0 2 4 ] = [ 2 3 2 4 7 10 ] \begin {bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end {bmatrix} + \begin {bmatrix} 1 & 1 & -1 \\ 0 & 2 & 4 \end {bmatrix} = \begin {bmatrix} 2 & 3 & 2 \\ 4 & 7 & 10 \end {bmatrix} \nonumber

If the sizes do not match, then addition is not defined.

If we denote by 0 the matrix of with all zero entries, by c,dc, d scalars, and by A,B,CA, B, C matrices, we have the following familiar rules.

A + 0 = A = 0 + A A + B = B + A ( A + B ) + C = A + ( B + C ) c ( A + B ) = c A + c B ( c + d ) A = c A + d A \begin{align}\begin{aligned} A + 0 &= A = 0 + A \\ A + B &= B + A \\ (A + B) + C &= A + ( B + C) \\ c( A + B) &= cA + cB \\ ( c + d) A &= cA + dA \end{aligned}\end{align} \nonumber

Another useful operation for matrices is the so-called transpose. This operation just swaps rows and columns of a matrix. The transpose of AA is denoted by ATA^T. Example:

[ 1 2 3 4 5 6 ] T = [ 1 4 2 5 3 6 ] { \begin {bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end {bmatrix}}^T = \begin {bmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end {bmatrix} \nonumber

Matrix Multiplication

Let us now define matrix multiplication. First we define the so-called dot product (or inner product) of two vectors. Usually this will be a row vector multiplied with a column vector of the same size. For the dot product we multiply each pair of entries from the first and the second vector and we sum these products. The result is a single number. For example,

[ a 1 a 2 a 3 ] · [ b 1 b 2 b 3 ] = [ a 1 b 1 + a 2 b 2 + a 3 b 3 ] \begin {bmatrix} a_1 & a_2 & a_3 \end {bmatrix} \cdot \begin {bmatrix} b_1 \\ b_2 \\ b_3 \end {bmatrix} = \begin {bmatrix} a_1b_1 + a_2b_2 + a_3b_3 \end {bmatrix} \nonumber

And similarly for larger (or smaller) vectors.

Armed with the dot product we can define the product of matrices. First let us denote by rowi(A)\text {row}_i (A) the ithi^{th} row of AA and by columnj(A)\text {column}_j (A) the jthj^{th} column of AA. For an m×nm \times n matrix AA and an n×pn \times p matrix BB we can define the product ABAB. We let ABAB be an m×pm \times p matrix whose ijthij^{th} entry is

row i ( A ) · column j ( B ) \text {row}_i (A) \cdot \text {column}_j (B) \nonumber

Do note how the sizes match up. Example:

[ 1 2 3 4 5 6 ] [ 1 0 1 1 1 1 1 0 0 ] = = [ 1 · 1 + 2 · 1 + 3 · 1 1 · 0 + 2 · 1 + 3 · 0 1 · ( 1 ) + 2 · 1 + 3 · 0 4 · 1 + 5 · 1 + 6 · 1 4 · 0 + 5 · 1 + 6 · 0 4 · ( 1 ) + 5 · 1 + 6 · 0 ] = [ 6 2 1 15 5 1 ] \begin{gathered} \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} \begin{bmatrix} 1 & 0 & -1 \\ 1 & 1 & 1 \\ 1 & 0 & 0 \end{bmatrix} = \\ = \begin{bmatrix} 1\cdot 1 + 2\cdot 1 + 3 \cdot 1 & & 1\cdot 0 + 2\cdot 1 + 3 \cdot 0 & & 1\cdot (-1) + 2\cdot 1 + 3 \cdot 0 \\ 4\cdot 1 + 5\cdot 1 + 6 \cdot 1 & & 4\cdot 0 + 5\cdot 1 + 6 \cdot 0 & & 4\cdot (-1) + 5\cdot 1 + 6 \cdot 0 \end{bmatrix} = \begin{bmatrix} 6 & 2 & 1 \\ 15 & 5 & 1 \end{bmatrix}\end{gathered} \nonumber

For multiplication we want an analog of a 1. This analog is the so-called identity matrix. The identity matrix is a square matrix with 1s on the main diagonal and zeros everywhere else. It is usually denoted by II. For each size we have a different identity matrix and so sometimes we may denote the size as a subscript. For example, the I3I_3 would be the 3×33 \times 3 identity matrix

I = I 3 = [ 1 0 0 0 1 0 0 0 1 ] I = I_3 = \begin {bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end {bmatrix} \nonumber

We have the following rules for matrix multiplication. Suppose that A,B,CA, B, C are matrices of the correct sizes so that the following make sense. Let α\alpha denote a scalar (number).

A ( B C ) = ( A B ) C A ( B + C ) = A B + A C ( B + C ) A = B A + C A α ( A B ) = ( α A ) B = A ( α B ) I A = A = A I \begin{align}\begin{aligned} A (BC) &= (AB) C\\ A (B + C) &= AB + AC \\ (B + C) A &= BA + CA \\ \alpha (AB) &= ( \alpha A )B = A ( \alpha B) \\ IA &= A = AI \end{aligned}\end{align} \nonumber

A few warnings are in order.

  1. ABBAAB \ne BA in general (it may be true by fluke sometimes). That is, matrices do not commute. For example take A=[1111]A = \begin {bmatrix} 1 & 1 \\ 1 & 1 \end {bmatrix} and B=[1002]B = \begin {bmatrix} 1 & 0 \\ 0 & 2 \end {bmatrix}.
  2. AB=ACAB = AC does not necessarily imply B=CB = C, even if AA is not 0.
  3. AB=0AB = 0 does not necessarily mean that A=0A = 0 or B=0B = 0. For example take A=B=[0100]A = B = \begin {bmatrix} 0 & 1 \\ 0 & 0 \end {bmatrix}.

For the last two items to hold we would need to “divide” by a matrix. This is where the matrix inverse comes in. Suppose that AA and BB are n×nn \times n matrices such that

A B = I = B A AB = I = BA \nonumber

Then we call BB the inverse of AA and we denote BB by A1A^{-1}. If the inverse of AA exists, then we call AA invertible. If AA is not invertible we sometimes say AA is singular.

If AA is invertible, then AB=ACAB = AC does imply that B=CB = C (in particular the inverse of AA is unique). We just multiply both sides by A1A^{-1} to get A1AB=A1ACA^{-1} AB = A^{-1} AC or IB=ICIB = IC or B=CB = C. It is also not hard to see that (A1)1=A{(A^{-1})}^{-1} = A.

3.2.3Determinant

We can now talk about determinants of square matrices. We define the determinant of a 1×11 \times 1 matrix as the value of its only entry. For a 2×22 \times 2 matrix we define

det ( [ a b c d ] ) = def a d b c \text {det} \left ( \begin {bmatrix} a & b \\ c & d \end {bmatrix} \right ) \overset {\text {def}}{=} ad - bc \nonumber

Before trying to compute the determinant for larger matrices, let us first note the meaning of the determinant. Consider an n×nn \times n matrix as a mapping of the nn dimensional euclidean space Rn\mathbb {R}^n to Rn\mathbb {R}^n. In particular, a 2×22 \times 2 matrix AA is a mapping of the plane to itself, where x\vec {x} gets sent to AxA \vec {x}. Then the determinant of AA is the factor by which the area of objects gets changed. If we take the unit square (square of side 1) in the plane, then AA takes the square to a parallelogram of area det(A)\mid \text {det} (A) \mid. The sign of det(A)\text {det} (A) denotes changing of orientation (negative if the axes got flipped). For example, let

A = [ 1 1 1 1 ] A = \begin {bmatrix} 1 & 1 \\ -1 & 1 \end {bmatrix} \nonumber

Then det(A)=1+1=2\text {det} (A) = 1 + 1 = 2. Let us see where the square with vertices (0,0),(1,0),(0,1)(0, 0), (1, 0), (0, 1) and (1,1)(1, 1) gets sent. Clearly (0,0)(0, 0 ) gets sent to (0,0)(0, 0).

[ 1 1 1 1 ] [ 1 0 ] = [ 1 1 ] , [ 1 1 1 1 ] [ 0 1 ] = [ 1 1 ] , [ 1 1 1 1 ] [ 1 1 ] = [ 2 0 ] \begin {bmatrix} 1 & 1 \\ -1 & 1 \end {bmatrix} \begin {bmatrix} 1 \\ 0 \end {bmatrix} = \begin {bmatrix} 1 \\ -1 \end {bmatrix}, \quad \begin {bmatrix} 1 & 1 \\ -1 & 1 \end {bmatrix} \begin {bmatrix} 0 \\ 1 \end {bmatrix} = \begin {bmatrix} 1 \\ 1 \end {bmatrix},\quad \begin {bmatrix} 1 & 1 \\ -1 & 1 \end {bmatrix} \begin {bmatrix} 1 \\ 1 \end {bmatrix} = \begin {bmatrix} 2 \\ 0 \end {bmatrix} \nonumber

So the image of the square is another square. The image square has a side of length 2\sqrt {2} and is therefore of area 2.

If you think back to high school geometry, you may have seen a formula for computing the area of a parallelogram with vertices (0,0),(a,c),(b,d)(0, 0), (a, c), (b, d) and (a+b,c+d)(a + b, c + d ). And it is precisely

| det ( [ a b c d ] ) | \left| \text {det} \left ( \begin {bmatrix} a & b \\ c & d \end {bmatrix} \right ) \right| \nonumber

The vertical lines above mean absolute value. The matrix [abcd]\begin {bmatrix} a & b \\ c & d \end {bmatrix} carries the unit square to the given parallelogram.

Now we can define the determinant for larger matrices. We define AijA_{ij} as the matrix AA with the ithi^{th} row and the jthj^{th} column deleted. To compute the determinant of a matrix, pick one row, say the ithi^{th} row and compute.

det ( A ) = j = 1 n ( 1 ) i + j a i j det ( A i j ) \text {det} (A) = \sum _ {j=1}^n (-1)^{i+j} a_{ij} \text {det} (A_{ij}) \nonumber

For the first row we get

det ( A ) = a 11 det ( A 11 ) a 12 det ( A 12 ) + a 13 det ( A 13 ) { + a 1 n det ( A 1 n if n is odd a 1 n det ( A 1 n if n even \text {det} (A) = a_{11} \text {det} (A_{11}) - a_{12} \text {det} (A_{12}) + a_{13} \text {det} (A_{13}) - \dots \begin {cases} +a_{1n} \text {det} (A_{1n} & \text {if n is odd} \\ -a_{1n} \text {det} (A_{1n} & \text {if n even} \end {cases} \nonumber

We alternately add and subtract the determinants of the submatrices AijA_{ij} for a fixed ii and all jj. For a 3×33 \times 3 matrix, picking the first row, we would get det(A)=a11det(A11)a12det(A12)+a13det(A13)\text {det} (A) = a_{11} \text {det} (A_{11}) - a_{12} \text {det} (A_{12}) + a_{13} \text {det} (A_{13}). For example,

det ( [ 1 2 3 4 5 6 7 8 9 ] ) = 1 · det ( [ 5 6 8 9 ] ) 2 · det ( [ 4 6 7 9 ] ) + 3 · det ( [ 4 5 7 8 ] ) = 1 ( 5 · 9 6 · 8 ) 2 ( 4 · 9 6 · 7 ) + 3 ( 4 · 8 5 · 7 ) = 0 \begin{align}\begin{aligned} \text {det} \left ( \begin {bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end {bmatrix} \right ) &= 1 \cdot \text {det} \left ( \begin {bmatrix} 5 & 6 \\ 8 & 9 \end {bmatrix} \right ) - 2 \cdot \text {det} \left ( \begin {bmatrix} 4 & 6 \\ 7 & 9 \end {bmatrix} \right ) + 3 \cdot \text {det} \left ( \begin {bmatrix} 4 & 5 \\ 7 & 8 \end {bmatrix} \right ) \\ &= 1(5 \cdot 9 - 6 \cdot 8) - 2 ( 4 \cdot 9 - 6 \cdot 7) + 3 ( 4 \cdot 8 - 5 \cdot 7 ) = 0 \end{aligned}\end{align} \nonumber

The numbers (1)i+jdet(Aij)(-1)^{i+j} \text {det} (A_{ij}) are called cofactors of the matrix and this way of computing the determinant is called the cofactor expansion. It is also possible to compute the determinant by expanding along columns (picking a column instead of a row above).

Note that a common notation for the determinant is a pair of vertical lines:

[ a b c d ] = det ( [ a b c d ] ) \begin {bmatrix} a & b \\ c & d \end {bmatrix} = \text {det} \left ( \begin {bmatrix} a & b \\ c & d \end {bmatrix} \right ) \nonumber

I personally find this notation confusing as vertical lines usually mean a positive quantity, while determinants can be negative. I will not use this notation in this book. One of the most important properties of determinants (in the context of this course) is the following theorem.

Think of the determinants telling you the scaling of a mapping. If BB doubles the sizes of geometric objects and AA triples them, then ABAB (which applies BB to an object and then AA) should make size go up by a factor of 66. This is true in general:

det(AB)=det(A)det(B).\det(AB) = \det(A)\det(B). \nonumber

This property is one of the most useful, and it is employed often to actually compute determinants. A particularly interesting consequence is to note what it means for existence of inverses. Take AA and BB to be inverses of each other, that is AB=IAB=I. Then

det(A)det(B)=det(AB)=det(I)=1.\det(A)\det(B) = \det(AB) = \det(I) = 1. \nonumber

Neither det(A)\det(A) nor det(B)\det(B) can be zero. Let us state this as a theorem as it will be very important in the context of this course.

In fact, there is a formula for the inverse of a 2×22 \times 2 matrix

[ a b c d ] 1 = 1 a d b c [ d b c a ] {\begin {bmatrix} a & b \\ c & d \end {bmatrix}}^ {-1} = \frac {1}{ad - bc} \begin {bmatrix} d & -b \\ -c & a \end {bmatrix} \nonumber

Notice the determinant of the matrix in the denominator of the fraction. The formula only works if the determinant is nonzero, otherwise we are dividing by zero.

Solving Linear Systems

One application of matrices we will need is to solve systems of linear equations. This is best shown by example. Suppose that we have the following system of linear equations

2 x 1 + 2 x 2 + 2 x 3 = 2 x 1 + x 2 + 3 x 3 = 5 x 1 + 4 x 2 + x 3 = 10 \begin{align}\begin{aligned} 2x_1 + 2x_2 + 2x_3 &= 2 \\ x_1 + x_2 + 3x_3 &= 5\\ x_1 + 4x_2 + x_3 &= 10\end{aligned}\end{align} \nonumber

Without changing the solution, we could swap equations in this system, we could multiply any of the equations by a nonzero number, and we could add a multiple of one equation to another equation. It turns out these operations always suffice to find a solution.

It is easier to write the system as a matrix equation. Note that the system can be written as

[ 2 2 2 1 1 3 1 4 1 ] [ x 1 x 2 x 3 ] = [ 2 5 10 ] \begin {bmatrix} 2 & 2 & 2 \\ 1 & 1 & 3 \\ 1 & 4 & 1 \end {bmatrix} \begin {bmatrix} x_1 \\ x_2 \\ x_3 \end {bmatrix} = \begin {bmatrix} 2 \\ 5 \\ 10 \end {bmatrix} \nonumber

To solve the system we put the coefficient matrix (the matrix on the left hand side of the equation) together with the vector on the right and side and get the so-called augmented matrix

[ 2 2 2 2 1 1 3 5 1 4 1 10 ] \left [ \begin {array}{ccc|c} 2 & 2 & 2 & 2 \\ 1 & 1 & 3 & 5 \\ 1 & 4 & 1&10 \end {array} \right ] \nonumber

We apply the following three elementary operations.

  1. Swap two rows.
  2. Add a multiple of one row to another row.
  3. Multiply a row by a nonzero number.

We will keep doing these operations until we get into a state where it is easy to read off the answer, or until we get into a contradiction indicating no solution, for example if we come up with an equation such as 0=10 = 1.

Let us work through the example. First multiply the first row by 12\frac {1}{2} to obtain

[ 1 1 1 1 1 1 3 5 1 4 1 10 ] \left [ \begin {array}{ccc|c} 1 & 1 & 1 & 1 \\ 1 & 1 & 3 & 5 \\ 1 & 4 & 1&10 \end {array} \right ] \nonumber

Now subtract the first row from the second and third row.

[ 1 1 1 1 0 0 2 4 0 3 0 9 ] \left [ \begin {array}{ccc|c} 1 & 1 & 1 & 1 \\ 0 & 0 & 2 & 4 \\ 0 & 3 & 0 & 9 \end {array} \right ] \nonumber

Multiply the last row by 13\frac {1}{3} and the second row by 12\frac {1}{2}.

[ 1 1 1 1 0 0 1 2 0 1 0 3 ] \left [ \begin {array}{ccc|c} 1 & 1 & 1 & 1 \\ 0 & 0 & 1 & 2 \\ 0 & 1 & 0 & 3 \end {array} \right ] \nonumber

Swap rows 2 and 3.

[ 1 1 1 1 0 1 0 3 0 0 1 2 ] \left [ \begin {array}{ccc|c} 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 3 \\ 0 & 0 & 1 & 2 \end {array} \right ] \nonumber

Subtract the last row from the first, then subtract the second row from the first.

[ 1 0 0 4 0 1 0 3 0 0 1 2 ] \left [ \begin {array}{ccc|c} 1 & 0 & 0 & -4 \\ 0 & 1 & 0 & 3 \\ 0 & 0 & 1 & 2 \end {array} \right ] \nonumber

If we think about what equations this augmented matrix represents, we see that x1=4,x2=3x_1 = -4, x_2 = 3 and x3=2x_3 = 2. We try this solution in the original system and, voilà, it works!

We write this equation in matrix notation as

Ax=b,A \vec{x} = \vec{b}, \nonumber

where AA is the matrix [222113141]\left[ \begin{smallmatrix} 2 & 2 & 2 \\ 1 & 1 & 3 \\ 1 & 4 & 1 \end{smallmatrix} \right] and b\vec{b} is the vector [2510]\left[ \begin{smallmatrix} 2 \\ 5 \\ 10 \end{smallmatrix} \right]. The solution can also be computed via the inverse,

x=A1Ax=A1b.\vec{x} = A^{-1} A \vec{x} = A^{-1} \vec{b}. \nonumber

It is possible that the solution is not unique, or that no solution exists. It is easy to tell if a solution does not exist. If during the row reduction you come up with a row where all the entries except the last one are zero (the last entry in a row corresponds to the right-hand side of the equation), then the system is inconsistent and has no solution. For example, for a system of 3 equations and 3 unknowns, if you find a row such as [000|1][\,0 \quad 0 \quad 0 ~\,|\,~ 1\,] in the augmented matrix, you know the system is inconsistent. That row corresponds to 0=10=1.

You generally try to use row operations until the following conditions are satisfied. The first (from the left) nonzero entry in each row is called the leading entry.

  1. The leading entry in any row is strictly to the right of the leading entry of the row above.
  2. Any zero rows are below all the nonzero rows.
  3. All leading entries are 11.
  4. All the entries above and below a leading entry are zero.

Such a matrix is said to be in reduced row echelon form. The variables corresponding to columns with no leading entries are said to be free variables. Free variables mean that we can pick those variables to be anything we want and then solve for the rest of the unknowns.

Computing the Inverse

If the coefficient matrix is square and there exists a unique solution x\vec {x} to Ax=bA \vec {x} = \vec {b} for any b\vec {b}, then AA is invertible. In fact by multiplying both sides by A1A^{-1} you can see that x=A1b\vec {x} = A^{-1} \vec {b}. So it is useful to compute the inverse if you want to solve the equation for many different right hand sides b\vec {b}.

The 2×22 \times 2 inverse can be given by a formula, but it is also not hard to compute inverses of larger matrices. While we will not have too much occasion to compute inverses for larger matrices than 2×22 \times 2 by hand, let us touch on how to do it. Finding the inverse of AA is actually just solving a bunch of linear equations. If we can solve Axk=ekA \vec {x}_k = \vec {e}_k where ek\vec {e}_k is the vector with all zeros except a 1 at the kthk^{th} position, then the inverse is the matrix with the columns xk\vec {x}_k for k=1,,nk = 1, \dots, n (exercise: why?). Therefore, to find the inverse we can write a larger n×2nn \times 2n augmented matrix [AI][ A \mid I ], where II is the identity. We then perform row reduction. The reduced row echelon form of [AI][ A \mid I ] will be of the form [IA1][ I \mid A^{-1} ] if and only if AA is invertible. We can then just read off the inverse A1A^{-1}.

Adapted from Differential Equations for Engineers by Jiří Lebl (https://www.jirka.org/diffyqs/), © Jiří Lebl, licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.