Chapter 2 Matrices

# 2.5 Matrix Calculator

Learning Objectives

By the end of this section, you should be able to:

• Use a matrix calculator
• to solve systems of equations
• for basic operations
• to solve systems with inverses

In Sections 2.2 through 2.4, you learned how to solve systems using matrices, perform basic matrix operations, and solve systems with inverses by hand. There are many resources that can be used to perform different matrix operations. One free resource is the Desmos Matrix Calculator. You can use the link to open a new webpage with the calculator or use the calculator that is located in the Back Matter of this textbook.

To create a matrix in the matrix calculator,

1. Click the $\begin{array}{|c|}\hline \text{New Matrix}\\ \hline \end{array}\;$ button.
2. Define the size of the matrix using the $\begin{array}{|c|}\hline -\\ \hline \end{array}\;$ and $\begin{array}{|c|}\hline +\\ \hline \end{array}\;$ buttons next to Row and Column.
3. Fill in the elements of the matrix.

The matrix calculator is useful in finding row-echelon form, performing basic operations, and solving systems with inverses.

# Reduced Row-Echelon Form

In Section 2.2, we worked problems where we found row-echelon form by hand. When using a matrix calculator, you can find the reduced row-echelon form, which can help you solve systems of equations. The reduced row-echelon is similar to row-echelon form, but the ones in the main diagonal are the only nonzero numbers in each column. To find the reduced row-echelon form in the matrix calculator,

1. Create a matrix.
2. Click the $\begin{array}{|c|}\hline \text{rref}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$.
3. Note that if you created more than one matrix, you will have to choose the appropriate letter based on what you named the matrix. So, if you want to find the reduced echelon form of matrix C, you’ll click $\begin{array}{|c|}\hline \text{rref}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{C}\\ \hline \end{array}\;$.

## Examples from Section 2.2

Only the Examples that involve solving systems

Example 4

Solve the given system by Gaussian elimination.

$\begin{cases}2x+3y=6\\x-y=\frac{1}{2}\end {cases}$

First we write this as an augmented matrix.

$\left[ \begin{array}{cc|c} 2&3&6\\1&-1&\frac{1}{2} \end{array} \right ]$

Create matrix A in the calculator by clicking $\begin{array}{|c|}\hline \text{New Matrix}\\ \hline \end{array}\;$. The augmented matrix is a $2 \times 3$ matrix, so add one column to matrix A, and fill in the entries. Note that the vertical line of the augmented matrix will not be in matrix A in the calculator.

Click $\begin{array}{|c|}\hline \text{rref}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$, and the calculator will find the row-echelon form of the matrix. By clicking the button next to the solution, you can convert fractions to decimals and decimals to fractions.

Therefore, $\text{rref}(\text{A})=\left[ \begin{array}{cc|c} 1&0& \frac{3}{2}\\0&1&1 \end{array} \right ]$. From the first row, we see that $x=\frac{3}{2}$, and from the second row, we see that $y=1$, making the solution the point $(\frac{3}{2}, 1)$.

Example 5

Use Gaussian elimination to solve the given system of equations.

$\begin{cases}2x+y=1\\4x+2y=6 \end{cases}$

Write the system as an augmented matrix.

$\left[ \begin{array}{cc|c}2&1&1\\4&2&6 \end{array}\right ]$

Create matrix A in the calculator by clicking $\begin{array}{|c|}\hline \text{New Matrix}\\ \hline \end{array}\;$. The augmented matrix is a $2 \times 3$ matrix, so add one column to matrix A, and fill in the entries.

Click $\begin{array}{|c|}\hline \text{rref}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$, and the calculator will find the row-echelon form of the matrix. By clicking the button next to the solution, you can convert fractions to decimals and decimals to fractions.

So, $\text{rref}(\text{A})=\left[ \begin{array}{cc|c} 1& \frac{1}{2}&0\\0&0&1 \end{array} \right ]$.

The second row represents the equation $0=1$. Therefore, the system is inconsistent and has no solution.

Example 6

Solve the system of equations.

$\begin{cases}3x+4y=12\\6x+8y=24\end{cases}$

Write the system as an augmented matrix.

$\left[ \begin{array}{cc|c}2&1&1\\4&2&6 \end{array}\right ]$

Create matrix A in the calculator by clicking $\begin{array}{|c|}\hline \text{New Matrix}\\ \hline \end{array}\;$. The augmented matrix is a $2 \times 3$ matrix, so add one column to matrix A, and fill in the entries.

Click $\begin{array}{|c|}\hline \text{rref}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$, and the calculator will find the row-echelon form of the matrix.

So, $\text{rref}(\text{A})=\left[ \begin{array}{cc|c} 1& \frac{4}{3}&4\\0&0&0 \end{array} \right ]$.

The matrix ends up with all zeros in the last row. Thus, there are an infinite number of solutions, and the system is classified as dependent. To find the generic solution, return to one of the original equations and solve for $y$.

$\begin {array}{rcl}3x+4y&=&12\\4y&=&12-3x\\y&=&3-\frac{3}{4}x \end{array}$

So the solution to this system is $(x, 3-\frac{3}{4}x)$.

Example 8

Solve the system of linear equations using matrices.

$\begin {cases}x-y+z=8\\2x+3y-z=-2\\3x-2y-9z=9\end{cases}$

First, we write the augmented matrix.

$\left[ \begin{array}{ccc|c}1&-1&1&8\\2&3&-1&-2\\3&-2&-9&9\end{array} \right]$

Create matrix A in the matrix calculator. The size of matrix A is $3 \times 4$.

Click $\begin{array}{|c|}\hline \text{rref}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$ to find the reduced row-echelon form of matrix A.

So, $\text{rref}(\text{A})=\left[ \begin{array}{ccc|c}1&0&0&4\\0&1&0&-3\\0&0&1&1\end{array} \right]$. Therefore, the solution to the system is $(4, -3, 1)$.

Example 9

Peter is planning on investing in what’s called a three-fund portfolio, consisting of a U.S. stock mutual fund, an international stock mutual fund, and a bond mutual fund. He has a total of $200,000 to invest and wants four times as much invested in stocks as in bonds. The bond fund has a historical return of 4.4%, the U.S. stock fund has a historical return of 8.3%, and the international stock fund has a historical return of 5.4%. If Peter is hoping for a$13,300 return, how should he allocate his investment?

Of course, historical returns cannot predict future earnings, but they’re the best information we have, so we’ll use them.

We have a system of three equations in three variables.

Let $x$ be the amount invested in U.S. stocks at 8.3% return, and

let $y$ be the amount invested in international stock at 5.4% return.

Let $z$ be the amount invested in the bond fund at 4.4% return.

We have a total of $200,000 to invest, so $x+y+z=200,000$ He wants four times as much invested in stocks as in bonds, so $\begin{array}{rcl}x+y&=&4z\\x+y-4z&=&0 \end{array}$ And using the return rates and the desired earnings, $0.083x+0.054y+0.044z=13,300$ We can take this system and put it into an augmented matrix. $A=\left[ \begin{array}{ccc|c}1&1&1&200,000\\1&1&-4&0\\0.083&0.054&0.044&13,300\end{array}\right]$ By plugging matrix A into the calculator and finding the reduced row-echelon form, we get $\text{rref}(\text{A})=\left[ \begin{array}{ccc|c}1&0&0&100,000\\0&1&0&60,000\\0&0&1&40000\end{array}\right]$ The first row tells us $x=100,000$. The second row tells us $y=60,000$, and the third row tells us $z=40,000$. Therefore,$100,000 should be invested in U.S. stock, $60,000 in international stock, and$40,000 in bonds.

Example 10

Solve the following system of linear equations using matrices.

$\begin{cases}-x-2y+z=-1\\2x+3y=2\\y-2z=0 \end{cases}$

Write the augmented matrix.

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

By plugging matrix A into the calculator and finding the reduced row-echelon form, we get $\text{rref}(\text{A})=\left[ \begin{array}{ccc|c}1&0&3&1\\0&1&-2&0\\0&0&0&0\end{array}\right]$

This matrix represents the following system.

$\begin{array}{rcl}x+2y-z&=&1\\y-2z&=&0\\0&=&0 \end{array}$

We see by the identity $0=0$ that this is a dependent system with an infinite number of solutions. We then find the generic solution. By solving the second equation for $y$ and substituting it into the first equation, we can solve for $z$ in terms of $x$.

$\begin{array}{rcl}x+2y-z&=&1\\y&=&2z\\ \\ x+2(2z)-z&=&1\\x+3z&=&1\\z&=&\frac{1-x}{3} \end{array}$

Now we substitute the expression for $z$ into the second equation to solve for $y$ in terms of $x$.

$\begin{array}{rcl}y-2z&=&0\\z&=&\frac{1-x}{3}\\ \\y-2(\frac{1-x}{3})&=&0\\y&=&\frac{2-2x}{3}\end{array}$

The generic solution is $(x, \frac{2-2x}{3}, \frac{1-x}{3})$.

# Basic Operations

Basic operations were done by hand in Section 2.3. To perform basic operations in the matrix calculator, start by creating two matrices, matrix A and matrix B. After the matrices are created, use the $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$ and $\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$ buttons along with the operations buttons to simplify the operations. For instance, if you wanted to know $A \times B$, you would first create matrix A and matrix B, then click $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$.

## Examples from Section 2.3

Example 2

Given $A$ and $B$:

$A=\begin{bmatrix}2&-10&-2\\14&12&10\\4&-2&2\end{bmatrix}$ and $B=\begin{bmatrix}6&10&-2\\0&-12&-4\\-5&2&-2\end{bmatrix}$

a) Find the sum.

Create matrices A and B in the calculator by clicking $\begin{array}{|c|}\hline \text{New Matrix}\\ \hline \end{array}\;$.

Click $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline +\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$, and the result is the sum of the two matrices.

Therefore, $A+B=\begin{bmatrix}8&0&-4\\14&0&6\\-1&0&0\end{bmatrix}$.

b) Find the difference.

Matrices A and B have already been created in the calculator. To find the difference, click $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline -\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$.

The result is the difference of matrices A and B.

So, $A-B=\begin{bmatrix}-4&-20&0\\14&24&14\\9&-4&4\end{bmatrix}$.

Example 3

Multiply matrix $A$ by the scalar 3.

$A=\left[\begin{array}{cc}8&1\\5&4 \end{array}\right]$

Create matrix A in the matrix calculator.

Click $\begin{array}{|c|}\hline \text{3}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$.

Therefore, $3A=\left[\begin{array}{cc}24&3\\15&12\end{array}\right]$.

Example 4

Find the sum $3A+2B$.

$A=\begin{bmatrix}1&-2&0\\0&-1&2\\4&3&-6 \end{bmatrix}$ and $B=\begin{bmatrix}-1&2&1\\0&-3&2\\0&1&-4 \end{bmatrix}$

Create A and B in the matrix calculator.

Click $\begin{array}{|c|}\hline \text{3}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline +\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{2}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$.

$3A+2B=\begin{bmatrix}1&-2&2\\0&-9&10\\12&11&-26\end{bmatrix}$

Example 5

Multiply matrix $A$ and matrix $B.$

$A=\begin{bmatrix} 1&2\\3&4 \end {bmatrix}$ and $\begin{bmatrix} 5&6\\7&8 \end{bmatrix}$

First, we check the dimensions of the matrices.

Matrix $A$ has dimensions $2 \times 2$, and matrix $B$ has dimensions $2 \times 2$. The inner dimensions are the same, so we can perform the multiplication. The product will have the dimensions $2 \times 2$.

Input matrices A and B in the matrix calculator.

Click $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$.

The result is $A \times B =\begin{bmatrix}19&22\\43&50\end{bmatrix}$.

Example 6

Given $A$ and $B$:

$A=\begin{bmatrix} -1&2&3\\4&0&5 \end {bmatrix}$ and $B=\begin{bmatrix} 5&-1\\-4&0\\2&3 \end{bmatrix}$

a) Find $AB$.

As the dimensions of $A$ are $2 \times 3$ and the dimensions of $B$ are $3 \times 2$, these matrices can be multiplied together because the number of columns in $A$ matches the number of rows in $B$. The resulting product will be a $2 \times 2$ matrix, the number of rows in $A$ by the number of columns in $B$.

Input matrices A and B in the calculator.

Click $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$.

The result is $A \times B =\begin{bmatrix}-7&10\\30&11\end{bmatrix}$.

b) Find $BA$.

The dimensions of $B$ are $3 \times 2$, and the dimensions of $A$ are $2 \times 3$. The inner dimensions match, so the product is defined and will be a $3 \times 3$ matrix.

Matrices A and B have already been entered into the calculator. Simply click $\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$.

The result is $B \times A =\begin{bmatrix}-9&10&10\\4&-8&-12\\10&4&21\end{bmatrix}$.

Example 7

Let’s return to the problem presented at the opening of Section 2.3. We have the table below representing the equipment needs of two soccer teams.

$\begin{array}{lcc} &\text{Wildcats}&\text{Mud Cats}\\ \text{Goals}&6&10\\ \text{Balls} &30&24\\ \text{Jerseys}&14&20 \end{array}$

We are also given the prices of the equipment, as shown below.

$\begin{array}{cc} \text{Goal}& \300\\ \text{Ball}&10\\ \text{Jersey}&30 \end{array}$

We will convert the data to matrices. Thus, the equipment need matrix is written as

$E=\begin{bmatrix} 6&10\\30&24\\14&20 \end{bmatrix}$

The cost matrix is written as

$C=\begin{bmatrix} 300&10&30\end{bmatrix}$

When putting these matrices into the calculator, matrix E was input as matrix A, and matrix C was input as matrix B.

We perform matrix multiplication to obtain costs for the equipment. Due to the dimensions of the matrices, we have to multiply $\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$.

The total cost for equipment for the Wildcats is $2,520, and the total cost for equipment for the Mud Cats is$3,840.

# Inverses

Inverses were used to solve systems of equations in Section 2.4. To find an inverse in the matrix calculator, start by creating matrix A. Click $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$ $\begin{array}{|c|}\hline \text{A} ^{-1}\\ \hline \end{array}\;$.

## Examples from Section 2.4

Example 1

Given matrix $A$, show that $AI=IA=A$.

$A=\begin{bmatrix} 3&4\\-2&5\end{bmatrix}$

Use matrix multiplication to show that the product of  and the identity is equal to the product of the identity and A.

Create matrix A in the calculator, and input matrix A. Then create matrix B in the calculator, and input the identity matrix.

When we type $\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$ and $\begin{array}{|c|}\hline \text{B}\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \times\\ \hline \end{array}\;$$\begin{array}{|c|}\hline \text{A}\\ \hline \end{array}\;$, we see that $AI=\begin{bmatrix} 3&4\\-2&5\end{bmatrix}=IA$.

Example 2

Show that the given matrices are multiplicative inverses of each other.

$A=\begin{bmatrix} 1&5\\-2&-9\end{bmatrix}$, $B=\begin{bmatrix} -9&-5\\2&1\end{bmatrix}$

Multiply $AB$ and $BA$. If both products equal the identity, then the two matrices are inverses of each other.

Because $AB=BA=I$, the matrices are inverses of each other.

Example 3

Given $A=\begin{bmatrix}2&1\\5&3\end{bmatrix}$, augment $A$ with the identity $\left[ \begin{array}{cc|cc}2&1&1&0\\5&3&0&1\end{array}\right]$. Find the reduced row-echelon form to turn A into the identity.

Create a new matrix in the calculator that is $2 \times 4$. We will call this matrix A in the calculator. Let $A=\begin{bmatrix} 2&1&1&0\\5&3&0&1\end{bmatrix}$.

By finding reduced row-echelon form, we can find the inverse of A.

So, $A^{-1} = \begin{bmatrix} 3&-1\\-5&2\end{bmatrix}$.

Example 4

Use the formula to find the multiplicative inverse of

$A=\begin{bmatrix}2&1\\5&3\end{bmatrix}$

Using the formula, we have

$\begin{array}{rcl}A^{-1}&=&\frac{1}{(2)(3)-(5)(1)}\begin{bmatrix}3&-1\\-5&2\end{bmatrix}\\ &=&\frac{1}{1}\begin{bmatrix}3&-1\\-5&2\end{bmatrix}\\ &=&\begin{bmatrix}3&-1\\-5&2\end{bmatrix}\\ \end{array}$

We can also find the inverse without using the formula if we choose to use the matrix calculator. To input the $A^{-1}$ in the calculator, we can input matrix A in the calculator, then click $\begin{array}{|c|}\hline A\\ \hline \end{array}\;$$\begin{array}{|c|}\hline A^{-1}\\ \hline \end{array}\;$.

Notice this matches the inverse we found above by augmenting with the identity matrix.

Example 5

Find the inverse, if it exists, of the given matrix: $A=\begin{bmatrix} 3&6\\1&2\end{bmatrix}$.

Input the matrix into the matrix calculator, then click $\begin{array}{|c|}\hline A\\ \hline \end{array}\;$$\begin{array}{|c|}\hline A^{-1}\\ \hline \end{array}\;$.

Notice that there is an error when you try to input $A^{-1}$. This means that there is no inverse of matrix A.

Example 6

Given the $3\times3$ matrix $A$, find the inverse.

$A=\begin{bmatrix}2&3&1\\3&3&1\\2&4&1\end{bmatrix}$

Input the matrix into the calculator and click $\begin{array}{|c|}\hline A\\ \hline \end{array}\;$$\begin{array}{|c|}\hline A^{-1}\\ \hline \end{array}\;$.

The inverse of matrix A is $A^{-1}=\begin{bmatrix}-1&1&0\\-1&0&1\\6&-3&-2\end{bmatrix}$.

Example 7

Solve the given system of equations using the inverse of a matrix.

$\begin{cases}3x+8y=5\\4x+11y=7\end {cases}$

Write the system in terms of a coefficient matrix, a variable matrix, and a constant matrix.

$A=\begin{bmatrix}3&8\\4&11\end{bmatrix}$, $X=\begin{bmatrix}x\\y\end{bmatrix}$, $B=\begin{bmatrix}5\\7\end{bmatrix}$

Input matrices A and B in the matrix calculator.

Then

$\begin{bmatrix}3&8\\4&11\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}=\begin{bmatrix}5\\7\end{bmatrix}$

First we have to calculate $A^{-1}$.

$A^{-1} = \begin{bmatrix}11&8\\-4&3\end{bmatrix}$

Now we are ready to solve. Multiply both sides of the equation by $A^{-1}$, and use the calculator to simplify all matrix multiplication.

$\begin{array}{rcl}(A^{-1})AX&=&(A^{-1})B\\ \begin{bmatrix}11&-8\\-4&3\end{bmatrix}\begin{bmatrix}3&8\\4&11\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}&=&\begin{bmatrix}11&-8\\-4&3\end{bmatrix}\begin{bmatrix}5\\7\end{bmatrix}\\ \begin{bmatrix}1&0\\0&1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}&=&\begin{bmatrix}-1\\1\end{bmatrix}\\ \begin{bmatrix}x\\y\end{bmatrix}&=&\begin{bmatrix}-1\\1\end{bmatrix}\\ \end{array}$.

The solution is $(-1,1)$.

Example 8

Solve the following system using the inverse of a matrix.

$\begin{cases}5x+15y+56z=35\\-4x-11y-41z=-26\\-x-3y-11z=-7\end {cases}$

Write the equation $AX=B$.

$\begin{bmatrix}5&15&56\\-4&-11&-41\\-1&-3&-11\end{bmatrix}\begin{bmatrix}x\\y\\z\end{bmatrix}=\begin{bmatrix}35\\-26\\-7\end{bmatrix}$

First, we will find the inverse of $A$ by augmenting with the identity.

$\left[ \begin{array}{ccc|ccc}5&15&56&1&0&0\\-4&-11&-41&0&1&0\\-1&-3&-11&0&0&1\end{array}\right]$

So, $A^{-1}=\begin{bmatrix}-2&-3&1\\-3&1&-19\\1&0&5\end{bmatrix}$.

Multiply both sides of the equation by $A^{-1}$. We want $A^{-1}AX=A^{-1}B$:

$\begin{bmatrix}-2&-3&1\\-3&1&-19\\1&0&5\end{bmatrix}\begin{bmatrix}5&15&56\\-4&-11&-41\\-1&-3&-11\end{bmatrix}\begin{bmatrix}x\\y\\z\end{bmatrix}=\begin{bmatrix}-2&-3&1\\-3&1&-19\\1&0&5\end{bmatrix}\begin{bmatrix}35\\-26\\-7\end{bmatrix}$

Thus,

$A^{-1}B=\begin{bmatrix}1\\2\\0\end{bmatrix}$

The solution is $(1,2,0)$.