## System of Equations, Part 4

Please read the previous posts on this topic if you do not understand this one.

To illustrate the power of matrices, consider the following system of equations:

w + x + y + z = 5
w + 2xy + 2z = 10
2w – 2xy + 3z = 11
2w + x + y – 3z = 0

This would take a while using the substitution or elimination methods. I will solve this using the matrix method. This system, in matrix form, is:

$\left[{\begin{array}{cccc}{1}&{1}&{1}&{1}\\{1}&{2}&{{-}{1}}&{2}\\{2}&{{-}{2}}&{{-}{1}}&{3}\\{2}&{1}&{1}&{{-}{3}}\end{array}}\right]\left[{\begin{array}{c}{w}\\{x}\\{y}\\{z}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{5}\\{10}\\{11}\\{0}\end{array}}\right]$

This system is in the form Ax = b and as shown in my last post, the solution to this is found by pre-multiplying both side by A-1. Now admittedly, finding A-1 manually for a 4 × 4 matrix would take some time. However, taking advantage of the internet (or a modern calculator), I find that

${\mathbf{A}}^{{-}{1}}\hspace{0.33em}{=}\hspace{0.33em}\frac{1}{59}\left[{\begin{array}{cccc}{1}&{4}&{12}&{15}\\{4}&{16}&{{-}{1}{1}}&{1}\\{39}&{{-}{2}{1}}&{{-}{4}}&{{-}{5}}\\{15}&{1}&{3}&{{-}{11}}\end{array}}\right]$

Here I factored out the 1/59 out of each element in the matrix to make it look nicer.

So from my last post, you know that the answer is found by pre-multiplying the b matrix:

Ax = bA-1Ax = A-1bIx = A-1bx = A-1b

So the solution is:

${\mathbf{x}}\hspace{0.33em}{=}\hspace{0.33em}{\mathbf{A}}^{{-}{1}}{\mathbf{b}}\hspace{0.33em}{=}\hspace{0.33em}\frac{1}{59}\left[{\begin{array}{cccc}{1}&{4}&{12}&{15}\\{4}&{16}&{{-}{1}{1}}&{1}\\{39}&{{-}{2}{1}}&{{-}{4}}&{{-}{5}}\\{15}&{1}&{3}&{{-}{11}}\end{array}}\right]\hspace{0.33em}\left[{\begin{array}{c}{5}\\{10}\\{11}\\{0}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{3}\\{1}\\{{-}{1}}\\{2}\end{array}}\right]$

So w = 3, x = 1, y = -1, and z = 2. Isn’t that fantastic!

## System of Equations, Part 3

So now that you know about matrices, we can use them to add a third way to solve a system of equations. You will need to read my previous 3 posts on matrices if you are unfamiliar with how to multiply matrices.

In the last post on System of Equations, I looked at the system:

2x + 3y = 51
3x + 2y = 49

And in my last post on Matrices, I showed you how a 2×2 matrix of numbers and a 2×1 matrix of unknowns can be multiplied together to get a 2×1 matrix that looks suspiciously like the left sides of a system of equations. This is , in fact, true. If I form a matrix using the coefficients on the left side of the above system, I get a matrix which I will call A:

${\textbf{A}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{2}&{3}\\{3}&{2}\end{array}}\right]$

Let me now define a matrix x (which is different from the single variable x which is in italics and not bold):

${\textbf{x}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{x}\\{y}\end{array}}\right]$

Now I will define a matrix b:

${\textbf{b}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{51}\\{49}\end{array}}\right]$

Now see what happens if I multiply A by x:

${\textbf{A}}{\textbf{x}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{2}&{3}\\{3}&{2}\end{array}}\right]\times\left[{\begin{array}{c}{x}\\{y}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{{2}{x}{+}{3}{y}}\\{{3}{x}{+}{2}{y}}\end{array}}\right]$

The rows of this result look just like the left side of our system of equations. And b is the right side. So the matrix equivalent of the system is

$\begin{array}{c} {{\textbf{A}}{\textbf{x}}\hspace{0.33em}{=}\hspace{0.33em}{\textbf{b}}}\\ {\left[{\begin{array}{cc}{2}&{3}\\{3}&{2}\end{array}}\right]\left[{\begin{array}{c}{x}\\{y}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{51}\\{49}\end{array}}\right]} \end{array}$

This is easy to form directly. You just form A as the matrix of coefficients (with the unknowns in the same order in each equation), x is the matrix of unknowns, and b is the matrix of the numbers on the right sides. So how do we solve this?

From my last post, I defined the inverse of a matrix A as A-1. This is the matrix that if I multiply A by its inverse, I get the identity matrix which is the equivalent of “1” in scalar maths.

The process of isolating (solving) for variables in a matrix equation is exactly the same as for scalar equations: you do the same thing to both sides with the goal of having the unknowns by themselves on one side. So if I pre-multiply (remember, order of multiplication in matrix maths is important) both sides of our matrix equation by A-1, the left side is the identity matrix times x which is equal to just x. The right side multiplies out to form the solution.

As I said before, finding A-1 is beyond the scope of this set of posts. I will just tell you what it is. However, many modern calculators will do this for you, and you can also use the internet and search for “matrix inverse calculator”. It turns out that A-1 is:

$\left[{\begin{array}{cc}{\frac{{-}{2}}{5}}&{\frac{3}{5}}\\{\frac{3}{5}}&{\frac{{-}{2}}{5}}\end{array}}\right]$

So taking the matrix equation and pre-multiply both sides by A-1 gives

A-1Ax = A-1bIx = A-1bx = A-1b

$\left[{\begin{array}{cc}{\frac{{-}{2}}{5}}&{\frac{3}{5}}\\{\frac{3}{5}}&{\frac{{-}{2}}{5}}\end{array}}\right]\left[{\begin{array}{cc}{2}&{3}\\{3}&{2}\end{array}}\right]\left[{\begin{array}{c}{x}\\{y}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{\frac{{-}{2}}{5}}&{\frac{3}{5}}\\{\frac{3}{5}}&{\frac{{-}{2}}{5}}\end{array}}\right]\left[{\begin{array}{c}{51}\\{49}\end{array}}\right]$ $\Longrightarrow\hspace{0.33em}\left[{\begin{array}{c}{x}\\{y}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{\frac{{-}{2}}{5}}&{\frac{3}{5}}\\{\frac{3}{5}}&{\frac{{-}{2}}{5}}\end{array}}\right]\left[{\begin{array}{c}{51}\\{49}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{9}\\{11}\end{array}}\right]$

Which is the same answer as before, x = 9 and y = 11.

This is a very powerful method for large systems of equations. Next time I will solve a system of 4 equations with 4 unknowns. For those of you who have done this manually, you will appreciate the ease matrix algebra provides.

## Matrices, Part 3

In my last post, I multiplied a 2 × 2 matrix by another 2 × 2 matrix. Now let’s multiply a 2 × 2 matrix by a 2 × 1 matrix. If you were paying attention last time, this is possible because the inside dimensions are the same (2= 2) and the resulting matrix will be a 2 × 1 matrix, that is, the outside dimensions.

This is done exactly the same way as illustrated in my last post, only there is only 1 column in the second matrix to multiply with the first matrix:

$\left[{\begin{array}{cc}{1}&{{-}{2}}\\{3}&{{-}{4}}\end{array}}\right]\hspace{0.33em}\times\hspace{0.33em}\left[{\begin{array}{c}{5}\\{6}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{{(}{5}\times{1}{)}{+}{(}{6}\times{(}{-}{2}{))}}\\{{(}{5}\times{3}{)}{+}{(}{6}\times{(}{-}{4}{))}}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{{-}{7}}\\{{-}{9}}\end{array}}\right]$

Now let the second matrix be composed of variables. This does not change the method at all. It just means that the result is a matrix with algebraic expressions:

$\left[{\begin{array}{cc}{1}&{{-}{2}}\\{3}&{{-}{4}}\end{array}}\right]\hspace{0.33em}\times\hspace{0.33em}\left[{\begin{array}{c}{x}\\{y}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{{(}{x}\times{1}{)}{+}{(}{y}\times{(}{-}{2}{))}}\\{{(}{x}\times{3}{)}{+}{(}{y}\times{(}{-}{4}{))}}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{c}{{x}{-}{2}{y}}\\{{3}{x}{-}{4}{y}}\end{array}}\right]$

Please keep this example in mind for my next post when I use matrices to solve a system of equations.

The last skill I need to present is matrix division. When using matrices, you do not actually divide a matrix by another matrix. Rather, you multiply by the inverse of a matrix.

In scalar arithmetic, you can think of dividing a number say 4, by another number, say 2, as multiplying the 4 by the inverse (reciprocal) of 2:

$\frac{4}{2}\hspace{0.33em}{=}\hspace{0.33em}{4}\hspace{0.33em}\times\hspace{0.33em}\frac{1}{2}\hspace{0.33em}{=}\hspace{0.33em}{2}$

The same thing is done with matrices. However, finding the inverse of a matrix is a little involved and I will not cover that in this set of posts. Rather I will just give you the result when needed. However I will say a few things about the properties of matrix inverses.

In scalar arithmetic, multiplying a number by it’s reciprocal (inverse) equals 1:

$\frac{2}{2}\hspace{0.33em}{=}\hspace{0.33em}{2}\hspace{0.33em}\times\hspace{0.33em}\frac{1}{2}\hspace{0.33em}{=}\hspace{0.33em}{1}$

The same thing is true with matrices, only what is “1” in the matrix world?

The equivalent “1” for matrices is the Identity Matrix. This is a square (rows = columns) matrix with 1’s down its diagonal and 0’s everywhere else:

$\left[{\begin{array}{cc}{1}&{0}\\{0}&{1}\end{array}}\right]$

This is the identity matrix for a 2 × 2 matrix. The inverse of a matrix is that matrix where multiplying it by the original matrix, results in the identity matrix. The inverse of a matrix A, is denoted as A-1.

${\mathbf{A}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]\hspace{0.33em}\hspace{0.33em}\hspace{0.33em}\hspace{0.33em}\hspace{0.33em}\hspace{0.33em}{\mathbf{A}}^{{-}{1}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{{-}{2}}&{1}\\{\frac{3}{2}}&{{-}\frac{1}{2}}\end{array}}\right]$ $\begin{array}{l} {{\mathbf{A}}\times{\mathbf{A}}^{{-}{1}}{=}\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]\times\left[{\begin{array}{cc}{{-}{2}}&{1}\\{\frac{3}{2}}&{{-}\frac{1}{2}}\end{array}}\right]{=}\left[{\begin{array}{cc}{{(}{-}{2}\times{1}{)}{+}{(}\frac{3}{2}\times{2}{)}}&{{(}{1}\times{1}{)}{+}{(}{-}\frac{1}{2}\times{2}{)}}\\{{(}{-}{2}\times{3}{)}{+}{(}\frac{3}{2}\times{4}{)}}&{{(}{1}\times{3}{)}{+}{(}{-}\frac{1}{2}\times{4}{)}}\end{array}}\right]}\\ {{=}\hspace{0.33em}\left[{\begin{array}{cc}{1}&{0}\\{0}&{1}\end{array}}\right]} \end{array}$

And it turns out that when multiplying a matrix by its inverse, order does not matter: A × A-1 = A-1 × A.

In my next post, I will put all this talk about matrices in practice and use them to solve a system of equations.

## Matrices, Part 2

In order to set up a system of equations using matrices, you need to understand how matrices multiply one another. Not all matrices can be multiplied together – they need to be compatible with one another. Not only that, unlike scalar (single number) arithmetic, multiplication does not commute, that is, the order of the multiplication will generally produce different results or one order may not even be possible. So what do I mean by compatible?

$\begin{array}{l} {\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]\times\left[{\begin{array}{cc}{5}&{6}\\{7}&{8}\end{array}}\right]\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{{(}{5}\times{1}{)}{+}{(}{7}\times{2}{)}}&{{(}{6}\times{1}{)}{+}{(}{8}\times{2}{)}}\\{{(}{5}\times{3}{)}{+}{(}{7}\times{4}{)}}&{{(}{6}\times{3}{)}{+}{(}{8}\times{4}{)}}\end{array}}\right]}\\ {{=}\hspace{0.33em}\left[{\begin{array}{cc}{19}&{22}\\{43}&{50}\end{array}}\right]} \end{array}$

To multiply these two 2 × 2 matrices, you take the first column of the second matrix and lay it over the top of the first matrix:

$\begin{array}{l} {\left[{\begin{array}{cc}{5}&{7}\end{array}}\right]}\\ {\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]} \end{array}$

Starting with the top row of the first matrix, Multiply the numbers in the same position together and add the result of each: (5 × 1) + (7 × 2) = 19. This result is the first row, first column number in the new matrix. Repeat this using the second row of the first matrix: (5 × 3) + (7 × 4) = 43. This is the first element of the second row of the new matrix. Now do the same with the second column of the second matrix:

$\begin{array}{l} {\left[{\begin{array}{cc}{6}&{8}\end{array}}\right]}\\ {\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]} \end{array}$

to get the second column of the new matrix. I will leave it as an exercise for you to confirm that if I reverse the order of the matrices, you will get a different result. That is,

$\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]\times\left[{\begin{array}{cc}{5}&{6}\\{7}&{8}\end{array}}\right]\hspace{0.33em}\ne\hspace{0.33em}\left[{\begin{array}{cc}{5}&{6}\\{7}&{8}\end{array}}\right]\hspace{0.33em}\times\hspace{0.33em}\left[{\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}}\right]$

So this method works for any size matrices as long as they are compatible. From this example, you see that this works only if the second matrix has the same number of rows as the number of columns in the first matrix. This is easy to see if you put the dimensions together: (2 × 2) × (2 × 2). The inside numbers need to be the same if multiplication is possible (2 = 2). The outside numbers give the dimensions of the resulting matrix (2 × 2).

So you can multiply a 3 × 2 matrix by a 2 × 4 matrix to get a 3 × 4 matrix, but you cannot reverse the order because the inside dimensions will not be equal. It’s interesting that if you multiply a 1 × (anything) matrix by a (same anything) × 1 matrix, you will get a 1 × 1 matrix which is just a number (a scalar).

This multiplication works even if some or all of the elements of the matrices are variables. I will illustrate this in my next post.

## Matrices, Part 1

In my two-part series on equation systems, I mentioned that there is a third method using matrices. Before I use this method, I have to explain what a matrix is. There is a whole new algebra surrounding matrices (the plural of matrix), so I will only explain what is needed to solve a system of equations.

All of the algebra we have used so far is called scalar algebra. That is, it is used on scalars. A scalar is just a single number like 3, -2.7, or x. It just has a value and you cannot get any more information from it like direction. In most engineering problems, 3-dimensional space is the playground and engineers are also interested in not only the speed of an object, but also the direction it is travelling in. Scalar algebra will not suffice. Enter matrix algebra. This is sometimes equated to linear algebra, but there are differences. I will continue to use matrix algebra as that is the most appropriate at this level.

A matrix is simply an array of numbers. Here are some examples:

$\left[{\begin{array}{cc}{{-}{1}}&{0}\\{3}&{2.4}\end{array}}\right]{,}\hspace{0.33em}\left[{\begin{array}{c}{0}\\{\sqrt{7}}\\{{-}{3}{.}{23}}\\{1}\end{array}}\right]{,}\hspace{0.33em}\left[{\begin{array}{ccc}{2}&{{-}{7}}&{0}\end{array}}\right]{,}\hspace{0.33em}\left[{\begin{array}{ccc}{2}&{0}&{3.8}\\{{-}{1}}&{0}&{0}\end{array}}\right]$

Of course, you cannot talk about a whole new field of maths without definitions. The first definition is dimension. The dimension of a matrix is its size. By convention, the dimension always indicates the number of rows first then the number of columns. So the first matrix in the examples above, is a 2 × 2 matrix because it has 2 rows and 2 columns. The second matrix is a 4 × 1 matrix. Matrices with 1 as one of the dimensions, can be called vectors as well. The third matrix is 1 × 3 and the last is 2 × 3.

It is very common to use bold typeface when using a single letter to represent a matrix so that the reader knows that they are talking about a matrix and not a scalar:

${\mathbf{A}}\hspace{0.33em}{=}\hspace{0.33em}\left[{\begin{array}{cc}{{-}{1}}&{0}\\{3}&{2.4}\end{array}}\right]$

So I can now talk about A and you know that A is a matrix.

So there are the same types of operations for matrices as there are for scalars: adding, subtracting, multiplying, and dividing. But there are rules associated with these matrix operations that are specific to matrices.

Since I am directing the use of matrices to solving a system of equations, I will only discuss the multiplying and dividing operations as they relate to matrices. This is where I will begin in my next post.