Homework 5: Matrices and Linear Transformations

due Sunday, October 18th at 11:59PM

Write your solutions to the following problems either by writing them on a piece of paper or on a tablet and scanning your answers as a PDF. Note that you are not allowed to use LaTeX, Google Docs, or any other digital document creation software to type your answers. Homeworks are due to Pensive by 11:59PM on the due date. See the syllabus for details on the slip day policy.

Homework will be evaluated not only on the correctness of your answers, but on your ability to present your ideas clearly and logically. You should always explain and justify your conclusions, using sound reasoning. Your goal should be to convince the reader of your assertions. If a question does not require explanation, it will be explicitly stated.

Before proceeding, make sure you’re familiar with the collaboration policy.


Problems


Total Points: \(6 + 8 + 9 + 8 + 8 + 6 + 12 + 6 + 8 + 9 + 20 = 100\)


Problem 1: Midterm 1 Solutions Reflection (6 pts)

Review the solutions to Midterm 1. Pick two problem parts in which your solutions have the most room for improvement: for example, where your reasoning was unsound or your presentation could have been clearer or more efficient. Include a screenshot of your solution to each part. For each, explain what was deficient and how to fix it.

Alternatively, if one of your solutions is significantly better than the posted one, include it and explain why. If you did not take Midterm 1, choose two challenging parts and explain the key ideas behind their solutions in your own words.

Solution

Problem 2: Matrix–Vector Practice (8 pts)

Compute each product, or explain why it is undefined. For each defined product, state the shape of the output. Show your arithmetic.

a)

(2 pts) \(\displaystyle \begin{bmatrix}4&-2&0&3\\-3&5&2&-1\\4&1&-5&2\end{bmatrix} \begin{bmatrix}-2\\3\\1\\-2\end{bmatrix}\)

b)

(2 pts) \(\displaystyle \begin{bmatrix}-8&0&0&0&0\\0&\frac32&0&0&0\\0&0&11&0&0\\0&0&0&-5&0\\0&0&0&0&7\end{bmatrix} \begin{bmatrix}3\\-4\\2\\6\\-3\end{bmatrix}\)

c)

(2 pts) \(\displaystyle \begin{bmatrix}12&-7&\frac12&9\end{bmatrix}\begin{bmatrix}3\\-2\\8\\-4\end{bmatrix}\)

d)

(2 pts) \(\displaystyle \begin{bmatrix}-5&8&3&12\\7&-2&6&-9\end{bmatrix}\begin{bmatrix}4\\-1\\5\end{bmatrix}\)

Solution

(a) To find each entry of the product, we multiply corresponding entries in a row of the matrix and the vector, then add:

$$ \begin{bmatrix} 4(-2)-2(3)+0(1)+3(-2)\\ -3(-2)+5(3)+2(1)-1(-2)\\ 4(-2)+1(3)-5(1)+2(-2) \end{bmatrix} =\boxed{\begin{bmatrix}-20\\25\\-14\end{bmatrix}} $$

The result has shape \(3\times1\).

(b) Recall that a diagonal matrix scales each coordinate separately. Here, we get

$$ \begin{bmatrix}-8(3)\\(3/2)(-4)\\11(2)\\-5(6)\\7(-3)\end{bmatrix} =\boxed{\begin{bmatrix}-24\\-6\\22\\-30\\-21\end{bmatrix}} $$

The result has shape \(5\times1\).

(c) Here, we multiply a \(1\times4\) row vector by a \(4\times1\) vector:

$$ 12(3)+(-7)(-2)+\tfrac12(8)+9(-4)=36+14+4-36=\boxed{18} $$

The output has shape \(1\times1\) and can be written as a scalar.

(d) Undefined. The matrix has four columns, but the input has only three entries. We would need one input entry for each of the four columns.


Problem 3: Is It Linear? (9 pts)

For each transformation, decide whether it is linear. A linear transformation must satisfy both properties below for all vectors \(\vec u,\vec v\) in its domain and all scalars \(c\):

  • Additivity: \(T(\vec u+\vec v)=T(\vec u)+T(\vec v)\).

  • Compatibility with scaling: \(T(c\vec v)=cT(\vec v)\).

For a linear transformation, state its associated matrix. For a nonlinear transformation, give a specific counterexample to at least one property. State your inputs and show that the two sides are different.

a)

(3 pts) \(T:\mathbb R^2\to\mathbb R^2\), defined by \(T\left(\begin{bmatrix}x\\y\end{bmatrix}\right) =\begin{bmatrix}(3x+2y)^2-9x^2-4y^2\\7x-5y\end{bmatrix}\).

Solution

Not linear. Expanding the first entry gives

$$ T\!\left(\begin{bmatrix}x\\y\end{bmatrix}\right) =\begin{bmatrix}12xy\\7x-5y\end{bmatrix} $$

For \(\vec u=\begin{bmatrix}1\\0\end{bmatrix}\) and \(\vec v=\begin{bmatrix}0\\1\end{bmatrix}\),

$$ T(\vec u+\vec v)=\begin{bmatrix}12\\2\end{bmatrix},\qquad T(\vec u)+T(\vec v)=\begin{bmatrix}0\\7\end{bmatrix}+\begin{bmatrix}0\\-5\end{bmatrix} =\begin{bmatrix}0\\2\end{bmatrix} $$

The two outputs are different, so \(T\) does not satisfy additivity. One counterexample is enough to show that \(T\) is not linear!

b)

(3 pts) \(T:\mathbb R^3\to\mathbb R^2\), defined by \(T\left(\begin{bmatrix}x\\y\\z\end{bmatrix}\right) =\begin{bmatrix}4(x-2y)+3(2y-z)\\5(x+z)-2(3x-y)\end{bmatrix}\).

Solution

We know that every linear transformation has an associated matrix, and multiplying by a matrix defines a linear transformation. Here,

$$ T\!\left(\begin{bmatrix}x\\y\\z\end{bmatrix}\right) =\begin{bmatrix}4x-2y-3z\\-x+2y+5z\end{bmatrix} =\underbrace{\begin{bmatrix}4&-2&-3\\-1&2&5\end{bmatrix}}_{\text{associated matrix}} \begin{bmatrix}x\\y\\z\end{bmatrix}, $$

so \(T\) is a linear transformation.

c)

(3 pts) \(T:\mathbb R^2\to\mathbb R^3\), defined by \(T\left(\begin{bmatrix}x\\y\end{bmatrix}\right) =\begin{bmatrix}6x-5y+8\\4(x+y)-7\\9x+2y-8\end{bmatrix}\).

Solution

Not linear. Compatibility with scaling fails when \(c=0\). For example, with \(\vec v=\begin{bmatrix}1\\1\end{bmatrix}\),

$$ T(0\vec v)=T(\vec0)=\begin{bmatrix}8\\-7\\-8\end{bmatrix} \ne\begin{bmatrix}0\\0\\0\end{bmatrix}=0T(\vec v) $$

In particular, a linear transformation must send \(\vec0\) to \(\vec0\).


Problem 4: Using the Fact That \(T\) Is a Linear Transformation (8 pts)

Let \(T:\mathbb R^3\to\mathbb R^2\) be a linear transformation, and let

$$ \vec u=\begin{bmatrix}2\\-1\\3\end{bmatrix},\qquad \vec v=\begin{bmatrix}-1\\2\\1\end{bmatrix}. $$

Suppose we know that

$$ T(3\vec u+\vec v)=\begin{bmatrix}8\\-1\end{bmatrix},\qquad T(2\vec u-3\vec v)=\begin{bmatrix}9\\-8\end{bmatrix}. $$

Use the fact that \(T\) is a linear transformation directly; you do not need to find the matrix of \(T\).

a)

(3 pts) Find \(T(\vec u)\) and \(T(\vec v)\). Show how you use the two given outputs.

Solution

Using the fact that \(T\) is a linear transformation, we can rewrite the two given equations as

$$ \begin{align*} 3T(\vec u)+T(\vec v)&=\begin{bmatrix}8\\-1\end{bmatrix},\\ 2T(\vec u)-3T(\vec v)&=\begin{bmatrix}9\\-8\end{bmatrix}. \end{align*} $$

We now have two equations in the two unknown vectors \(T(\vec u)\) and \(T(\vec v)\). To eliminate \(T(\vec v)\), multiply the first equation by \(3\):

$$ 9T(\vec u)+3T(\vec v)=3\begin{bmatrix}8\\-1\end{bmatrix} =\begin{bmatrix}24\\-3\end{bmatrix}. $$

Adding this equation to the second equation gives

$$ \bigl(9T(\vec u)+3T(\vec v)\bigr)+\bigl(2T(\vec u)-3T(\vec v)\bigr) =\begin{bmatrix}24\\-3\end{bmatrix}+\begin{bmatrix}9\\-8\end{bmatrix}, $$

so

$$ 11T(\vec u)=\begin{bmatrix}33\\-11\end{bmatrix} \quad\Longrightarrow\quad \boxed{T(\vec u)=\begin{bmatrix}3\\-1\end{bmatrix}}. $$

Now substitute this result into the first equation:

$$ 3\begin{bmatrix}3\\-1\end{bmatrix}+T(\vec v)=\begin{bmatrix}8\\-1\end{bmatrix}. $$

Subtracting \(3T(\vec u)\) from both sides gives

$$ T(\vec v)=\begin{bmatrix}8\\-1\end{bmatrix} -\begin{bmatrix}9\\-3\end{bmatrix} =\boxed{\begin{bmatrix}-1\\2\end{bmatrix}}. $$
b)

(3 pts) Find \(T\left(\begin{bmatrix}8\\-7\\7\end{bmatrix}\right)\). Explain how you express this input using \(\vec u\) and \(\vec v\).

Solution

Let’s write the input as \(a\vec u+b\vec v\). Matching the three entries gives

$$ 2a-b=8,\qquad -a+2b=-7,\qquad 3a+b=7 $$

The first two equations give \(a=3\) and \(b=-2\). These values also satisfy the third equation, so we can use the fact that \(T\) is a linear transformation:

$$ T\!\left(\begin{bmatrix}8\\-7\\7\end{bmatrix}\right) =T(3\vec u-2\vec v)=3\begin{bmatrix}3\\-1\end{bmatrix}-2\begin{bmatrix}-1\\2\end{bmatrix} =\boxed{\begin{bmatrix}11\\-7\end{bmatrix}} $$
c)

(2 pts) A student claims that \(T\left(\begin{bmatrix}3\\0\\7\end{bmatrix}\right)=\begin{bmatrix}5\\1\end{bmatrix}\). Is this consistent? Explain.

Solution

No. The input is \(2\vec u+\vec v\), so the fact that \(T\) is a linear transformation tells us that

$$ T\!\left(\begin{bmatrix}3\\0\\7\end{bmatrix}\right) =2T(\vec u)+T(\vec v) =2\begin{bmatrix}3\\-1\end{bmatrix}+\begin{bmatrix}-1\\2\end{bmatrix} =\boxed{\begin{bmatrix}5\\0\end{bmatrix}} $$

This is different from the claimed output.


Problem 5: Finding a Transformation’s Matrix (8 pts)

Let \(S:\mathbb R^2\to\mathbb R^2\) be a linear transformation satisfying

$$ S\!\left(\begin{bmatrix}2\\0\end{bmatrix}\right)=\begin{bmatrix}8\\6\end{bmatrix},\qquad S\!\left(\begin{bmatrix}0\\3\end{bmatrix}\right)=\begin{bmatrix}-9\\12\end{bmatrix}. $$
a)

(3 pts) Find \(S\left(\begin{bmatrix}1\\0\end{bmatrix}\right)\) and \(S\left(\begin{bmatrix}0\\1\end{bmatrix}\right)\), then construct the matrix of \(S\). Explain how you chose its columns.

Solution

By compatibility with scaling,

$$ S\!\left(\begin{bmatrix}1\\0\end{bmatrix}\right)=\tfrac12\begin{bmatrix}8\\6\end{bmatrix}=\begin{bmatrix}4\\3\end{bmatrix},\qquad S\!\left(\begin{bmatrix}0\\1\end{bmatrix}\right)=\tfrac13\begin{bmatrix}-9\\12\end{bmatrix}=\begin{bmatrix}-3\\4\end{bmatrix} $$

Recall that the columns of the associated matrix are the outputs for the standard basis vectors, in order. We just found those outputs, so

$$ \boxed{S(\vec x)=\begin{bmatrix}4&-3\\3&4\end{bmatrix}\vec x} $$
b)

(2 pts) Use your matrix to find \(S\left(\begin{bmatrix}3\\-2\end{bmatrix}\right)\).

Solution
$$ S\!\left(\begin{bmatrix}3\\-2\end{bmatrix}\right) =\begin{bmatrix}4&-3\\3&4\end{bmatrix}\begin{bmatrix}3\\-2\end{bmatrix} =\begin{bmatrix}12+6\\9-8\end{bmatrix} =\boxed{\begin{bmatrix}18\\1\end{bmatrix}} $$
c)

(3 pts) Describe the geometric effect of \(S\) in words, using the types of linear transformations we saw in Chapter 3.2 and Chapter 3.4. Specify any scale factor and, if there is a rotation, its direction and angle. You may specify an angle by giving its sine and cosine.

Solution

We can recognize this transformation by factoring out \(5\):

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

The second matrix is a rotation matrix with \(\cos\theta=4/5\) and \(\sin\theta=3/5\). So \(S\) rotates vectors counterclockwise by \(\theta\approx36.87^\circ\) and scales them by a factor of \(5\). Every length is multiplied by \(5\), and angles stay the same.


Problem 6: Can We Work Backward? (6 pts)

Let \(\displaystyle A=\begin{bmatrix}4&-6\\-2&3\end{bmatrix}\).

a)

(2 pts) Find two different inputs \(\vec u\) and \(\vec v\) such that \(A\vec u=A\vec v=\begin{bmatrix}12\\-6\end{bmatrix}\). Write the system of equations you are solving.

Solution

The system is

$$ 4x-6y=12,\qquad -2x+3y=-6 $$

The second equation is \(-1/2\) times the first, so it gives us no new information. Solving the first equation for \(x\) gives \(x=3+\tfrac32y\). Choosing \(y=0\) and \(y=2\), for example, gives

$$ \boxed{\vec u=\begin{bmatrix}3\\0\end{bmatrix},\qquad \vec v=\begin{bmatrix}6\\2\end{bmatrix}} $$

Indeed, both products are \(\begin{bmatrix}12\\-6\end{bmatrix}\).

b)

(2 pts) Is there an input with output \(\begin{bmatrix}12\\-5\end{bmatrix}\)? Explain using the columns of \(A\) and their span.

Solution

No. The second column is \(-3/2\) times the first, so every output is in

$$ \operatorname{span}\!\left(\begin{bmatrix}4\\-2\end{bmatrix}\right) $$

Every vector in this span has second entry equal to \(-1/2\) times its first entry. An output with first entry \(12\) must have second entry \(-6\), not \(-5\).

c)

(2 pts) Using your inputs from part (a), find a nonzero input with output \(\vec0\). Explain why your construction works using the fact that multiplication by \(A\) is a linear transformation.

Solution

The two inputs from part (a) have the same output. Let’s subtract them:

$$ \boxed{\vec v-\vec u=\begin{bmatrix}3\\2\end{bmatrix}} $$

This vector is nonzero. Using the fact that multiplication by \(A\) is a linear transformation, we get

$$ A(\vec v-\vec u)=A\vec v-A\vec u =\begin{bmatrix}12\\-6\end{bmatrix}-\begin{bmatrix}12\\-6\end{bmatrix}=\vec0 $$

Note: Problems 7–11 require material from Tuesday, October 13th’s lecture.

Problem 7: Matrix Products (12 pts)

Compute the requested products and state their shapes. Show your arithmetic.

a)

(4 pts) Let

$$ A=\begin{bmatrix}3&-2\\-1&4\\4&1\\2&-3\end{bmatrix},\qquad B=\begin{bmatrix}2&-3&1&2\\-2&1&4&-1\end{bmatrix}. $$

Compute both \(AB\) and \(BA\).

Solution

The product \(AB\) has shape \(4\times4\), while \(BA\) has shape \(2\times2\). Multiplying rows of the first matrix by columns of the second gives

$$ \boxed{AB=\begin{bmatrix}10&-11&-5&8\\-10&7&15&-6\\6&-11&8&7\\10&-9&-10&7\end{bmatrix}},\qquad \boxed{BA=\begin{bmatrix}17&-21\\7&15\end{bmatrix}} $$

For example, two of the entries are

$$ \begin{align*} (AB)_{1,1}&=3(2)+(-2)(-2)=10\\ (BA)_{1,1}&=2(3)+(-3)(-1)+1(4)+2(2)=17 \end{align*} $$

The other entries are computed in the same way.

b)

(4 pts) Let

$$ C=\begin{bmatrix}3&-2&4\\0&5&2\\0&0&-2\end{bmatrix},\qquad D=\begin{bmatrix}2&4&-3\\5&-2&1\\-4&3&2\end{bmatrix}. $$

Compute both \(CD\) and \(DC\).

Solution

Both products have shape \(3\times3\):

$$ \boxed{CD=\begin{bmatrix}-20&28&-3\\17&-4&9\\8&-6&-4\end{bmatrix}},\qquad \boxed{DC=\begin{bmatrix}6&16&22\\15&-20&14\\-12&23&-14\end{bmatrix}} $$

For example,

$$ \begin{align*} (CD)_{1,1}&=3(2)+(-2)(5)+4(-4)=-20\\ (CD)_{2,3}&=0(-3)+5(1)+2(2)=9\\ (DC)_{1,2}&=2(-2)+4(5)+(-3)(0)=16 \end{align*} $$

The shapes agree, but the entries show that \(CD\ne DC\).

c)

(4 pts) A mechanical engineer wants to measure how a beam bends when forces are applied at different locations. A test rig is a laboratory setup built to test a component under controlled conditions. This rig has three actuators, motor-driven devices that push or pull on the beam, and five sensors, devices that measure the beam’s vertical movement at five locations.

Coordinate diagram

In a simplified linear model, \(H\vec u\) gives the five sensor readings, in millimeters, when \(\vec u\) lists the forces applied by the three actuators, in newtons (N). For example, \(\vec u=\begin{bmatrix}2\\-3\\4\end{bmatrix}\) corresponds to the first actuator pushing upward with a force of \(2\) N, the second pulling downward with a force of \(3\) N, and the third pushing upward with a force of \(4\) N. Sensor readings are displacements from the beam’s unloaded position; positive readings mean upward movement.

The columns of \(U\) give the actuator forces for two separate trials:

$$ H=\begin{bmatrix} 3&-2&4\\-2&4&3\\5&1&-3\\3&-4&2\\-4&3&2 \end{bmatrix},\qquad U=\begin{bmatrix}2&-3\\-3&4\\4&2\end{bmatrix}. $$

Compute \(HU\). What does the entry in row 4, column 2 of your answer represent? Why is \(UH\) undefined? Write a sentence involving the actuators, sensors, and two trials; simply saying that the matrix shapes do not match is not enough.

Solution

The product has shape \(5\times2\): five sensors, with one column for each trial.

$$ \boxed{HU=\begin{bmatrix}28&-9\\-4&28\\-5&-17\\26&-21\\-9&28\end{bmatrix}} $$

For example,

$$ (HU)_{4,2}=3(-3)+(-4)(4)+2(2)=-9-16+4=\boxed{-21} $$

Thus, in trial 2, sensor 4 reads a displacement of \(-21\) mm: the beam moves 21 mm downward at that sensor.

The columns of \(U\) are two trials, each specifying forces for three actuators; the rows of \(H\) are five sensors. The reverse product \(UH\) would try to pair the two trial entries in a row of \(U\) with the five sensor entries in a column of \(H\). Those are different physical quantities and different numbers of entries, so they cannot form the required dot products.


Problem 8: Do the Usual Rules Still Work? (6 pts)

All matrices in this problem are \(2\times2\) and all vectors are in \(\mathbb R^2\). Justify each answer. A counterexample must include specific matrices or vectors and the relevant products.

Hint: It may help to complete Problem 6(c) first, where you find a nonzero vector whose product with a matrix is zero.

a)

(2 pts) If \(B\vec v=\vec0\), must \(AB\vec v=\vec0\)? If \(AB\vec v=\vec0\), must \(B\vec v=\vec0\)? Address both directions.

Solution

Yes to the first question, but no to the second. If \(B\vec v=\vec0\), then

$$ AB\vec v=A(B\vec v)=A\vec0=\vec0 $$

To see why the second statement can fail, we can reuse our example from Problem 6. Let

$$ A=\begin{bmatrix}4&-6\\-2&3\end{bmatrix},\qquad B=I,\qquad \vec v=\begin{bmatrix}3\\2\end{bmatrix} $$

Then \(AB\vec v=A\vec v=\vec0\), but \(B\vec v=\vec v\ne\vec0\). Multiplication by \(A\) can send a nonzero vector to zero.

b)

(2 pts) Can \(AB=0_{2\times2}\) even when neither \(A\) nor \(B\) is the zero matrix? Give an example or explain why it is impossible.

Solution

Yes. Use the nonzero vector from Problem 6(c) as a column of \(B\):

$$ A=\begin{bmatrix}4&-6\\-2&3\end{bmatrix},\qquad B=\begin{bmatrix}3&6\\2&4\end{bmatrix} $$

Both matrices are nonzero, but

$$ AB=\begin{bmatrix}12-12&24-24\\-6+6&-12+12\end{bmatrix} =\boxed{\begin{bmatrix}0&0\\0&0\end{bmatrix}} $$

Both columns of \(B\) are sent to zero by \(A\).

c)

(2 pts) Expand \((A+B)^2\) using distributivity, keeping the factors in their original order. Is it always equal to \(A^2+2AB+B^2\)? If not, give a counterexample.

Solution

We can distribute just as we would with numbers, but we need to keep the order of the matrices:

$$ \boxed{(A+B)^2=A^2+AB+BA+B^2} $$

This equals \(A^2+2AB+B^2\) only when \(BA=AB\). For a counterexample, let

$$ A=\begin{bmatrix}0&2\\0&0\end{bmatrix},\qquad B=\begin{bmatrix}0&0\\3&0\end{bmatrix} $$

Here \(A^2=B^2=0\), \(AB=\begin{bmatrix}6&0\\0&0\end{bmatrix}\), and \(BA=\begin{bmatrix}0&0\\0&6\end{bmatrix}\). Therefore,

$$ (A+B)^2=\begin{bmatrix}6&0\\0&6\end{bmatrix} \ne\begin{bmatrix}12&0\\0&0\end{bmatrix}=A^2+2AB+B^2 $$

Problem 9: Transforming a Triangle (8 pts)

Consider the triangle with vertices \(\begin{bmatrix}0\\0\end{bmatrix}\), \(\begin{bmatrix}4\\0\end{bmatrix}\), and \(\begin{bmatrix}0\\2\end{bmatrix}\). To transform it, transform its three vertices and connect their images.

Coordinate diagram

Let \(D\) stretch horizontally by a factor of \(2\), leaving vertical coordinates unchanged. Let \(Q\) rotate counterclockwise by \(45^\circ\) about the origin. Recall that the rotation matrix is

$$ \begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}. $$

Give exact matrix entries and vertex coordinates. You may use decimal approximations when drawing.

a)

(2 pts) Write the matrices \(Q\) and \(D\).

Solution
$$ \boxed{Q=\frac1{\sqrt2}\begin{bmatrix}1&-1\\1&1\end{bmatrix}},\qquad \boxed{D=\begin{bmatrix}2&0\\0&1\end{bmatrix}} $$
b)

(3 pts) Find the matrix for stretching first and then rotating. Draw the resulting triangle on a coordinate plane, labeling the coordinates of all three vertices.

Solution

First, we stretch \(\vec x\) to get \(D\vec x\). Then, we rotate that result to get \(Q(D\vec x)\). The matrix for the first transformation goes on the right, so the combined matrix is

$$ \boxed{QD=\frac1{\sqrt2}\begin{bmatrix}2&-1\\2&1\end{bmatrix}} $$

The three vertices become

$$ \begin{bmatrix}0\\0\end{bmatrix}\mapsto\begin{bmatrix}0\\0\end{bmatrix},\quad \begin{bmatrix}4\\0\end{bmatrix}\mapsto\begin{bmatrix}4\sqrt2\\4\sqrt2\end{bmatrix},\quad \begin{bmatrix}0\\2\end{bmatrix}\mapsto\begin{bmatrix}-\sqrt2\\\sqrt2\end{bmatrix} $$
image
c)

(3 pts) Reverse the order, find the new combined matrix, and draw the resulting triangle on a second coordinate plane with the same scale. Label the coordinates of all three vertices. Describe how the two transformed triangles differ.

Solution

Rotating first and stretching second gives

$$ \boxed{DQ=\frac1{\sqrt2}\begin{bmatrix}2&-2\\1&1\end{bmatrix}} $$

Now the vertices become

$$ \begin{bmatrix}0\\0\end{bmatrix}\mapsto\begin{bmatrix}0\\0\end{bmatrix},\quad \begin{bmatrix}4\\0\end{bmatrix}\mapsto\begin{bmatrix}4\sqrt2\\2\sqrt2\end{bmatrix},\quad \begin{bmatrix}0\\2\end{bmatrix}\mapsto\begin{bmatrix}-2\sqrt2\\\sqrt2\end{bmatrix} $$
image

The first triangle is taller and narrower. It still has a right angle at the origin: stretching along the original coordinate axes preserves that right angle, and rotating preserves all angles. In the second triangle, stretching after rotation changes the angle between the tilted sides, so the angle at the origin is no longer a right angle.


Problem 10: From Projection to Reflection (9 pts)

In Homework 4, Problem 9, you found that the reflection of a vector \(\vec v\) across a line can be written as

$$ \vec v_{\mathrm{ref}}=2\vec p-\vec v, $$

where \(\vec p\) is the projection of \(\vec v\) onto the line. Here’s the same picture again: the tip of \(\vec p\) is halfway between the tips of \(\vec v\) and \(\vec v_{\mathrm{ref}}\).

image

In Lab 6, you used the matrix

$$ P=\begin{bmatrix}w_1^2&w_1w_2\\w_1w_2&w_2^2\end{bmatrix} $$

to project onto a line spanned by a unit vector \(\vec w=\begin{bmatrix}w_1\\w_2\end{bmatrix}\). Thus \(\vec p=P\vec v\).

a)

(2 pts) Derive a matrix \(R\), expressed in terms of \(P\) and the identity matrix \(I\), such that \(R\vec v=\vec v_{\mathrm{ref}}\) for every \(\vec v\). Then write all four entries of \(R\) in terms of \(w_1,w_2\).

Solution

We know how to write the projection as a matrix-vector product: \(\vec p=P\vec v\). Substituting this into the reflection formula gives

$$ \vec v_{\mathrm{ref}}=2P\vec v-\vec v=(2P-I)\vec v $$

Since this holds for every input,

$$ \boxed{R=2P-I=\begin{bmatrix}2w_1^2-1&2w_1w_2\\2w_1w_2&2w_2^2-1\end{bmatrix}} $$
b)

(3 pts) Now use the line spanned by \(\vec w=\begin{bmatrix}3/5\\4/5\end{bmatrix}\). Find \(P\), \(R\), and the reflection of \(\vec v=\begin{bmatrix}7\\1\end{bmatrix}\) across this line.

Solution

Here, \(\vec w\) is already a unit vector, since \((3/5)^2+(4/5)^2=1\). We can substitute its entries directly into our formulas:

$$ \boxed{P=\frac1{25}\begin{bmatrix}9&12\\12&16\end{bmatrix}},\qquad \boxed{R=\frac1{25}\begin{bmatrix}-7&24\\24&7\end{bmatrix}} $$

The reflected vector is

$$ R\begin{bmatrix}7\\1\end{bmatrix} =\frac1{25}\begin{bmatrix}-7(7)+24(1)\\24(7)+7(1)\end{bmatrix} =\frac1{25}\begin{bmatrix}-25\\175\end{bmatrix} =\boxed{\begin{bmatrix}-1\\7\end{bmatrix}} $$
c)

(2 pts) What does \(R\) do to a vector parallel to the line? To a vector perpendicular to it? Explain using projections.

Solution

A vector parallel to the line is its own projection, so

$$ P\vec v=\vec v\quad\Longrightarrow\quad R\vec v=2\vec v-\vec v=\boxed{\vec v} $$

A vector perpendicular to the line has zero projection, so

$$ P\vec v=\vec0\quad\Longrightarrow\quad R\vec v=2\vec0-\vec v=\boxed{-\vec v} $$

Reflection preserves the parallel component and reverses the perpendicular component.

d)

(2 pts) Explain geometrically why \(P^2=P\) and \(R^2=I\). Then use \(P^2=P\) and your expression for \(R\) to verify \(R^2=I\) algebraically.

Solution

Once a vector has been projected onto the line, projecting it again changes nothing. Therefore \(P^2\vec v=P\vec v\) for every \(\vec v\), so \(P^2=P\).

Reflecting across the same line twice returns every vector to its original position, so \(R^2=I\). Algebraically,

$$ R^2=(2P-I)^2=4P^2-2P-2P+I=4P-4P+I=\boxed{I} $$

Problem 11: Programming Activity (20 pts)

Your goal here is to build a very basic image editing app, called Canva124, using what you’ve learned about linear transformations and matrix multiplication.

To open the notebook for Homework 5, click this link. Instructions on how to use Google Colab are at math124.org/running-code.

You won’t need to submit the notebook anywhere. To get credit, complete all five tasks in the notebook and include the requested screenshots in your PDF submission to Homework 5 on Pensive, specifically under Problem 11. The notebook specifies what to submit for each task:

  1. 1.

    Task 1 (0 pts; required): Grayscale.

  2. 2.

    Task 2 (5 pts): Sepia.

  3. 3.

    Task 3 (5 pts): Color tint.

  4. 4.

    Task 4 (5 pts): Stretching and shearing.

  5. 5.

    Task 5 (5 pts): Rotation.

Solution

Task 1: Grayscale. We’ve already implemented these two functions in the notebook:

def filter_pixel(A, u):
    return A @ u


def grayscale_matrix():
    return np.ones((3, 3)) / 3

For the example pixel,

$$ G\begin{bmatrix}60\\120\\210\end{bmatrix} =\frac13\begin{bmatrix}60+120+210\\60+120+210\\60+120+210\end{bmatrix} =\boxed{\begin{bmatrix}130\\130\\130\end{bmatrix}} $$

For example, \(\begin{bmatrix}60\\120\\210\end{bmatrix}\) and \(\begin{bmatrix}90\\150\\150\end{bmatrix}\) have the same grayscale output: the entries of each vector add up to \(390\). Knowing the average doesn’t tell us the three original color values, so we can’t always recover the original pixel.

Task 2: Sepia. Each row tells us how to compute one output color. We put the coefficients for red in the first row, green in the second, and blue in the third:

def sepia_matrix():
    return np.array([[0.393, 0.769, 0.189],
                     [0.349, 0.686, 0.168],
                     [0.272, 0.534, 0.131]])

The first row says that the new red value is \(0.393R+0.769G+0.189B\). The first column says that one unit of original red contributes \(0.393\) units to the new red value, \(0.349\) to green, and \(0.272\) to blue. These are the values before the app rounds them and limits them to the range from \(0\) to \(255\).

Task 3: Color tint. We want to scale each color separately, so we use a diagonal matrix:

def tint_matrix(rgb):
    r, g, b = rgb
    return np.array([[r / 255, 0, 0],
                     [0, g / 255, 0],
                     [0, 0, b / 255]])

A sample tint is \((255,153,51)\), with matrix \(\operatorname{diag}(1,0.6,0.2)\).

White gives \(\boxed{I_3}\), so the image is unchanged. Black gives \(\boxed{0_{3\times3}}\), so every pixel becomes black. To remove blue while preserving red and green, choose yellow:

$$ \boxed{\text{RGB}=(255,255,0),\qquad A=\begin{bmatrix}1&0&0\\0&1&0\\0&0&0\end{bmatrix}} $$

Task 4: Stretching and shearing. Each column of \(X\) holds one position vector. Multiplying \(AX\) transforms all of those vectors at once, which is why we can reuse the same function for stretching, shearing, and rotation:

def transform_points(A, X):
    return A @ X


def scale_matrix(sx, sy):
    return np.array([[sx, 0],
                     [0, sy]])

The horizontal shear is

def shear_matrix(k):
    return np.array([[1, k], [0, 1]])

For example, \(k=0.75\) sends \(\begin{bmatrix}x\\y\end{bmatrix}\) to \(\begin{bmatrix}x+0.75y\\y\end{bmatrix}\). The \(x\)-coordinate changes by \(0.75y\) and the \(y\)-coordinate stays fixed. Every point on the \(x\)-axis has \(y=0\), so it remains in place.

Task 5: Rotation. Recall the rotation matrix from Lab 6. The app already converts the slider’s angle to radians, so we can use theta directly:

def rotation_matrix(theta):
    c, s = np.cos(theta), np.sin(theta)
    return np.array([[c, -s], [s, c]])

One example uses the Rotate slider at \(30^\circ\), which rotates the image counterclockwise. A stretching example uses \(s_x=1.5\) and \(s_y=0.75\): the image becomes \(50\%\) wider and \(25\%\) shorter. These are separate selections in Canva124.

Optional connection to Problem 10. Reflection is not a task in the released notebook, but we can implement it using the matrix \(R=2P-I\) we found in Problem 10:

def reflection_matrix(theta):
    w1, w2 = np.cos(theta), np.sin(theta)
    P = np.array([[w1**2, w1*w2], [w1*w2, w2**2]])
    return 2 * P - np.eye(2)

For example, consider a line at \(30^\circ\) to the positive \(x\)-axis. The line has unit direction \(\vec w=\begin{bmatrix}\sqrt3/2\\1/2\end{bmatrix}\), and the reflection matrix is

$$ \boxed{R=\begin{bmatrix}1/2&\sqrt3/2\\\sqrt3/2&-1/2\end{bmatrix}} $$

Every point already on this line remains fixed: its projection is itself, so \(R\vec v=2\vec v-\vec v=\vec v\).

Below are example images for the five notebook tasks, along with the optional reflection above. Your images will depend on the picture and settings you chose.

Problem 11: Example image outputs

Each result below starts with the original sample image. Dashed outlines show the original image boundary. The reflection is an optional illustration of Problem 10; it was not required for Problem 11. Its dotted blue line shows the reflection axis.

image

Additionally, in class on Tuesday, October 13th, we will be visited by staff from the Foundational Course Initiative team, who will ask for your feedback on the course both in-person and through a form – the Mid-Semester Feedback form. Completing this form will earn you 0.5% of your overall course grade, as part of the 3% of your course grade that is dedicated to course improvement.

The Mid-Semester Feedback form is due on Friday, October 16th. Homework 5 is due Sunday, October 18th at 11:59PM. Math 124 staff will not see the results of the form directly; instead, the Foundational Course Initiative staff will summarize the results and share them with us.