07 Pre-Class Assignment: Inverse and Transformation Matrices#


Assignment Overview#

  1. Transpose

  2. Inverse

  3. Transformations


1. The Transpose of a Matrix#

Definition Given an \(m\times n\) matrix \(A\), the transpose of \(A\) is the \((n\times m)\) matrix \(A^T\), defined by $\( [A^T]_{ij} = [A]_{ji}, \)\( for \)1\leq i\leq m, 1\leq j\leq n$. For example

\[\begin{split} A = \left[ \begin{matrix} 1 & 2\\ 3 & 4 \end{matrix} \right] \qquad\Longrightarrow \qquad A^T = \left[ \begin{matrix} 1 & 3\\ 2 & 4 \end{matrix} \right] \end{split}\]
\[\begin{split} B = \left[ \begin{matrix} 1 & 2 & 30\\ 3 & 4 & 9 \end{matrix} \right] \qquad\Longrightarrow \qquad B^T = \left[ \begin{matrix} 1 & 3\\ 2 & 4 \\ 30 & 9 \end{matrix} \right] \end{split}\]

Note that the rows of \(A^T\) are the columns of \(A\), and the columns of \(A^T\) are the rows of \(A\), i.e., the transpose operation swaps rows and columns.

In Python, we can find the transpose of a matrix A (numpy array or matrix) by using A.T

QUESTION: Create the following matrix in numpy, and then find its transpose $\( \left[ \begin{matrix} 1 & 0 & 0\\ 2 & 3 & 0\\ 1 & 3 & 4\\ 1 & 9 & 7\\ \end{matrix} \right] \)$

Store the transposed matrix in a variable called Atranspose for the answercheck.

# Put your code here
from answercheck import checkanswer
checkanswer.matrix(Atranspose,"c280f7e2eaf174101b162d78350dce37")

2. The Inverse Matrix (a.k.a. \(A^{-1}\))#

For some (not all) square matrices \(A\), there exists a special matrix called the Inverse Matrix, which is typically written as \(A^{-1}\) and when multiplied by \(A\) results in the identity matrix \(I\):

\[ A^{-1}A = AA^{-1} = I. \]

Note that this is defined only for square matrices and thus, the matrices \(A\), \(A^{-1}\), and \(I\) above all have the same size.

Some properties of an Inverse Matrix include:

  1. \((A^{-1})^{-1} = A\)

  2. \((cA)^{-1} = \frac{1}{c}A^{-1}\)

  3. \((AB)^{-1} = B^{-1}A^{-1}\)

  4. \((A^n)^{-1} = (A^{-1})^n\)

  5. \((A^\top)^{-1} = (A^{-1})^\top\) here \(A^\top\) is the transpose of the matrix \(A\).

If you know that \(A^{-1}\) is an inverse matrix of \(A\), then solving \(Ax=b\) is simple, just multiply both sides of the equation by \(A^{-1}\) (on the left) and you get:

\[A^{-1}Ax = A^{-1}b\]

If we apply the definition of the inverse matrix from above we can reduce the equation to:

\[Ix = A^{-1}b\]

We know \(I\) times \(x\) is just \(x\) (definition of the identity matrix), so this further reduces to:

\[x = A^{-1}b\]

To conclude, solving \(Ax=b\) when you know \(A^{-1}\) is really simple. All you need to do is multiply \(A^{-1}\) by \(b\) and you know \(x\).

DO THIS: Find a Python numpy command that will calculate the inverse of a matrix and use it invert the following matrix A. Store the inverse in a new matirx named A_inv

import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True) # Trick to make matrixes look nice in jupyter

A = np.matrix([[1, 2, 3], [4, 5, 6], [7,8,7]])

sym.Matrix(A)
#put your answer to the above question here.

Let’s check your answer by multiplying A by A_inv.

A * A_inv
np.allclose(A*A_inv, [[1,0,0],[0,1,0],[0,0,1]])

QUESTION: What function did you use to find the inverse of matrix \(A\)?

Put your answer to the above question here

DO THIS: Now, consider the following matrix B. Try to find its inverse. Explain why you are getting the result you are getting.

import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True) # Trick to make matrixes look nice in jupyter

B = np.matrix([[1, 2, 3], [4, 5, 6], [2,4,6]])

sym.Matrix(B)

How do we create an inverse matrix?#

From previous assignments, we learned that we could string together a bunch of Elementary Row Operations to get matrix (\(A\)) into its Reduced Row Echelon Form. We later discussed that each Elementary Row Operation can be represented by a multiplication by an Elementary Matrix. Thus, the Gauss-Jordan Elimination (using Elementary Row Operations) can be represented as multiplication by a number of Elementary Matrices as follows:

\[ E_n \dots E_3 E_2 E_1 A = RREF \]

If \(A\) reduces to the identity matrix (i.e. \(A\) is row equivalent to \(I\), or \(RREF=I\)), then \(A\) has an inverse, and its inverse is just all of the Elementary Matrices multiplied together:

\[ A^{-1} = E_n \dots E_3 E_2 E_1 \]

Consider the following matrix.
$\( A = \left[ \begin{matrix} 1 & 2 \\ 4 & 6 \end{matrix} \right] \)$

A = np.matrix([[1, 2], [4,6]])

It can be reduced into an identity matrix using the following elementary operators

Words

Elementary Matrix

Adding -4 times row 1 to row 2.

$\(E_1 = \left[\begin{matrix}1 & 0 \\ -4 & 1 \end{matrix}\right]\)$

Adding row 2 to row 1.

$\( E_2 = \left[\begin{matrix}1 & 1 \\ 0 & 1 \end{matrix}\right] \)$

Multiplying row 2 by \(-\frac{1}{2}\).

$\(E_3 = \left[\begin{matrix}1 & 0 \\ 0 & -\frac{1}{2} \end{matrix}\right]\)$

E1 = np.matrix([[1,0], [-4,1]])
E2 = np.matrix([[1,1], [0,1]])
E3 = np.matrix([[1,0],[0,-1/2]])

We can just check that the statment seems to be true by multiplying everything out.

E3*E2*E1*A

DO THIS: Combine the above elementary Matrices to make an inverse matrix named A_inv

# Put your answer to the above question here.

DO THIS: Verify that A_inv is an actual inverse by checking that \(A^{-1}A = I\) and \(AA^{-1} = I\).

# Put your code here.

QUESTION: Is an invertible matrix is always square? Why or why not?

Put your answer to the above question here.

QUESTION: Is a square matrix always invertible? Why or why not?

Put your answer to the above question here.

QUESTION: Describe the Reduced Row Echelon Form of a square, invertible matrix.

Put your answer to the above question here.

QUESTION: Is the following matrix in the Reduced Row Echelon Form?

\[\begin{split} \left[ \begin{matrix} 1 & 2 & 0 & 3 & 0 & 4 \\ 0 & 0 & 1 & 3 & 0 & 7 \\ 0 & 0 & 0 & 0 & 1 & 6 \\ 0 & 0 & 0 & 0 & 0 & 0 \end{matrix} \right] \end{split}\]

Put your answer to the above question here.

QUESTION: If the matrix shown above is not in Reduced Row Echelon Form. Name a rule that is violated?

Put your answer to the above question here.

QUESTION: What is the size of the matrix described in the previous QUESTION?

  • \(4 \times 6\)

  • \(6 \times 4\)

  • \(3 \times 6\)

  • \(5 \times 3\)

Put your answer to the above question here.

QUESTION: Describe the Elementary Row Operation that is implemented by the following matrix

\[\begin{split} \left[ \begin{matrix} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{matrix} \right] \end{split}\]

Put your answer to the above question here.


3. Transformation Matrices#

Consider the following set of points:

%matplotlib inline
import matplotlib.pylab as plt

x = [0.0,  0.0,  2.0,  8.0, 10.0, 10.0, 8.0, 4.0, 3.0, 3.0, 4.0, 6.0, 7.0, 7.0, 10.0, 
     10.0,  8.0,  2.0, 0.0, 0.0, 2.0, 6.0, 7.0,  7.0,  6.0,  4.0,  3.0, 3.0, 0.0]
y = [0.0, -2.0, -4.0, -4.0, -2.0,  2.0, 4.0, 4.0, 5.0, 7.0, 8.0, 8.0, 7.0, 6.0,  6.0,
     8.0, 10.0, 10.0, 8.0, 4.0, 2.0, 2.0, 1.0, -1.0, -2.0, -2.0, -1.0, 0.0, 0.0]

plt.plot(x,y, color='green');
plt.axis('equal');

We can rotate these points around the origin by using the following simple set of equations:

\[ x \cos(\theta) - y \sin(\theta) = x_{\text{rotated}} \]
\[ x \sin(\theta) + y \cos(\theta) = y_{\text{rotated}} \]

This can be rewritten in the following matrix form:

\[\begin{split} \left[ \begin{matrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{matrix} \right] \left[ \begin{matrix} x \\ y \end{matrix} \right] = \left[ \begin{matrix} x_{\text{rotated}}\\ y_{\text{rotated}} \end{matrix} \right] \end{split}\]

We can rotate the points around the origin by \(\pi/4\) (i.e. \(45^\circ\)} as follows:

import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True) # Trick to make matrices look nice in jupyter

points = np.matrix([x,y])
angle = np.pi/4
R = np.matrix([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]]);
sym.Matrix(R)
p=R*points

plt.plot(p[0].T,p[1].T);
plt.axis('equal');

#print(p[0].T)

We can even have a little fun and keep applying the same rotation over and over again.

# Apply R and plot 8 times
for i in range(0,8):
    p = R * p
    plt.plot(p[0].T,p[1].T);

plt.axis('equal');

QUESTION: In the above code what does the T call in p[0].T do?

Put your answer here


Written by Dr. Dirk Colbry, Michigan State University Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

###STARTFOOTER###


Congratulations, we’re done!#