Skip to main content

Section 8.2 Matrices

Preview Activity 8.2.1.

Consider the following code generating a visualization of several vectors.

a = vector([1,-3,5])
b = vector([-4,2,3])
c = vector([3,0,4])

sum([plot(t/50*a+(50-t)/50*b,color='blue') for t in range(50+1)]) + \
    line([a,b],color='purple') + \
    sum([plot(t/50*b+(50-t)/50*c,color='red') for t in range(50+1)]) + \
    line([b,c],color='purple')
Listing 8.2.1. Visualizing a pair of vectors

(a)

Run 8.2.1 in a Code cell. Use your mouse to move the visualization around.

(b)

Are the vectors in the generated visualization two-dimensional or three-dimensional? Explain your reasoning.

(c)

Is your screen displaying this visualization two-dimensional or three-dimensional? Explain your reasoning.

(d)

Describe a form of entertainment where three-dimensional data is displayed in only two dimensions.

Activity 8.2.2.

Every two-dimensional vector can be decomposed into two standard basic vectors: \(\hat\imath=(1,0)\) and \(\hat\jmath=(0,1)\text{.}\)

(a)

Let veci=vector([1,0]) and vecj=vector([0,1]). Use a Code cell to verify that \((3,-4)=3\hat\imath-4\hat\jmath\text{.}\)

(b)

Rewrite the vector \((-12,5)\) using standard basic vectors \(\hat\imath\) and \(\hat\jmath\text{,}\) and confirm your result with a code cell.

(c)

Rewrite the complex number \(-6-5i\) using the standard basic vectors \(\hat\imath\) and \(\hat\jmath\text{.}\) Then write a sentence or two explaining why many engineers prefer to write complex numbers in \(a+bj\) form instead of \(a+bi\text{.}\)

(d)

Explain how to define \(\hat\imath,\hat\jmath,\hat{k}\) such that the vector \((2,3,4)\) may be rewritten as \(2\hat\imath+3\hat\jmath+4\hat{k}\text{.}\)

(e)

Write code defining veci_3d, vecj_3d, veck_3d, and then confirm that vector([2,3,4])==2*veci_3d+3*vecj_3d+4*veck_3d returns True.

Activity 8.2.3.

While \(\hat\imath,\hat\jmath,\hat{k}\) form the “standard” bases for 2D and 3D space, there are also non-standard bases. That is, a basis for 2D or 3D space is any collection of vectors that can describe all other vectors.

(a)

Modify the code in 8.2.2 so that it visualizes how the vectors \(-\hat\imath+3\hat\jmath\text{,}\) \(3\hat\imath+4\hat\jmath\text{,}\) and \(-2\hat\imath-5\hat\jmath\) appear in the standard 2D coordinate system.

basic1 = veci # first basic vector
basic2 = vecj # second basic vector

# draws part of coordinate system based on chosen basis
size = 6
sum(
    [line([n*basic1-size*basic2,n*basic1+size*basic2],color="#ddf") for n in range(-size,size+1)] + \
    [line([n*basic2-size*basic1,n*basic2+size*basic1],color="#ddf") for n in range(-size,size+1)] + \
    [line([-size*basic2,size*basic2],color="#88f"),line([-size*basic1,size*basic1],color="#88f")]
) + plot(basic1,color="#f88") + plot(basic2,color="#f88") + \
    plot(vector([-1,3]))
Listing 8.2.2. Drawing a coordinate system

(b)

Any pair of vectors forms a basis, provided they don't point in exactly the same (or opposite) directions.

Modify 8.2.2 to set basic1 and basic2 equal to the non-standard pair of basis vectors \(\vec b_1=(1,2)\) and \(\vec b_2=(-1,1)\text{,}\) and then visualize how the vectors \(-\vec b_1+3\vec b_2\text{,}\) \(3\vec b_1+4\vec b_2\text{,}\) and \(-2\vec b_1-5\vec b_2\) appear in this modified coordinate system.

(c)

Use the standard coordinate axes in visualization from the previous task to describe the vectors \(-\vec b_1+3\vec b_2\text{,}\) \(3\vec b_1+4\vec b_2\text{,}\) and \(-2\vec b_1-5\vec b_2\) using standard basic vectors/coordinates.

(d)

Use SageMath to calculuate standard coordinates for the vectors \(-\vec b_1+3\vec b_2\text{,}\) \(3\vec b_1+4\vec b_2\text{,}\) and \(-2\vec b_1-5\vec b_2\) directly, confirming the result you found from the illustration.

Activity 8.2.4.

The process of converting vectors from one basis to another is called a transformation. For example, the transformation of the vectors \(\hat\imath,\hat\jmath\) into the vectors \(\vec b_1,\vec b_2\) results in the vector \((-1,3)=-\hat\imath+3\hat\jmath\) in standard coordinates transforming into the vector \(-\vec b_1+3\vec b_2\) described with non-standard coordinates.

The transformation of the standard basis \(\hat\imath,\hat\jmath\) into the non-standard basis \(\vec b_1,\vec b_2\) is described by the matrix \(\left(\vec b_1\hspace{1em}\vec b_2\right)\) where the values of \(\vec b_1,\vec b_2\) are written vertically as columns. For example, the transformation of \(\hat\imath\) and \(\hat\jmath\) into \(\vec b_1=(1,2)\) and \(\vec b_2=(-1,1)\) is described by the matrix:

\begin{equation*} \left( \begin{matrix} 1 & -1 \\ 2 & 1 \end{matrix} \right) \end{equation*}

(a)

Show matrix([basic1,basic2]). Explain why this isn't exactly the matrix described above.

(b)

Use transpose() to save the matrix we actually want to the CS variable B.

(c)

The matrix multiplication described by \(\left(\vec b_1\hspace{1em}\vec b_2\right)(-1,3)= \left( \begin{matrix} 1 & -1 \\ 2 & 1 \end{matrix} \right) \left( \begin{matrix} -1 \\ 3 \end{matrix} \right)\) computes the transformation of \((-1,3)=-\hat\imath+3\hat\jmath\) into \(-\vec b_1+3\vec b_2\text{.}\) SageMath can compute this transformation by running B*vector([-1,3]).

Show how to use matrix multiplication to compute \(-\vec b_1+3\vec b_2\text{,}\) \(3\vec b_1+4\vec b_2\text{,}\) and \(-2\vec b_1-5\vec b_2\text{.}\)

(d)

Extend this idea to define a \(3\times 3\) matrix that transforms the 3D standard basic vectors \(\hat\imath,\hat\jmath,\hat{k}\) into the vectors \(\vec c_1=(1,2,3)\text{,}\) \(\vec c_2=(-2,0,3)\text{,}\) and \(\vec c_3=(-1,0,-1)\text{.}\)

(e)

Show how to compute \(4\vec c_1-3\vec c_2+2\vec c_3\) in SageMath using two different ways: one with matrix multiplication and one without.

Activity 8.2.5.

Matrices can also be used to transform 3D data into 2D data. For example, the matrix \(\left( \begin{matrix} 1 & -1 & 0 \\ 2 & 1 & 1 \end{matrix} \right)\) defined by A=matrix([[1,-1,0],[2,1,1]]) transforms the 3D standard basic vectors 3D standard basic vectors \(\hat\imath,\hat\jmath,\hat{k}\) into the 2D vectors \((1,2)\text{,}\) \((-1,1)\text{,}\) and \((0,1)\text{.}\)

(a)

In computer animation, objects can be represented by piecing together triangles of various colors. The SageMath code polygon([v1,v2,v3]) represents the triangle whose corners are pointed to by the vectors stored as the CS variables v1, v2, and v3.

Display the triangle whose corners are pointed to by the vectors \((1,2,3)\text{,}\) \((3,0,-1)\text{,}\) and \((-1,1,2)\text{.}\)

(b)

Use multiplication with the matrix \(\left( \begin{matrix} 1 & -1 & 0 \\ 2 & 1 & 1 \end{matrix} \right)\) to transform this triangle within 3D space into a triangle in 2D space.

(c)

Create more matrices and show how they transform the same triangle into different triangles in 2D space.

Exercises Exercises

1.

Describe the vector \((3,-2)\) using the 2D standard basic vectors \(\hat\imath,\hat\jmath\text{.}\)

2.

Describe the vector \((-5,1,2)\) using the 3D standard basic vectors \(\hat\imath,\hat\jmath,\hat{k}\text{.}\)

3.

Write SageMath code to define veci (in 2D), vecj (in 2D), veci_3d, vecj_3d, and veck_3d. Then use those to confirm your answer to the previous exercises.

4.

Let \(\vec w_1=(1,3)\) and \(\vec w_2=(5,-1)\text{.}\) Define a matrix in SageMath that can be used to transform \(\hat\imath\) to \(\vec w_1\) and \(\hat\jmath\) to \(\vec w_2\text{.}\)

5.

Use this matrix to compute each of the following:

  • \(\displaystyle 3\vec w_1+\vec w_2\)

  • \(\displaystyle 2\vec w_1-4\vec w_2\)

  • \(\displaystyle -4\vec w_1\)

  • \(\displaystyle -\vec w_1-5\vec w_2\)

6.

Compute each of the vector expressions in the previous exercise without using a matrix.

7.

Show how to compute the vector expression \(3(1,2,3)-5(0,1,1)+(4,0,3)\) with and without matrix multiplication in SageMath.

8.

Display the triangle with corners at the 3D coordinates \((1,2,3)\text{,}\) \((4,3,7)\text{,}\) and \((0,2,6)\text{.}\)

9.

Display the transformation of this shape into 2D space according to the matrix \(\left( \begin{matrix} -1 & 0 & 2 \\ 3 & -1 & -2 \end{matrix} \right) \text{.}\)