Part II

The

Example: Some \(2 \times 3\) matrices:

$$ \begin{bmatrix} 1 & 2 & 3\\4 & 5 & 6\end{bmatrix} \ \ \ \ \ \ \begin{bmatrix} -7 & 0 & 0.4\\ 0 & \pi & \sqrt{3}\end{bmatrix}$$

A

Note that a vector is really just a matrix with one row or one column.

As with vectors, the numbers in a matrix are called

We can refer to a particular entry by saying which row and column it's in: $$ \mbox{name of matrix}[\mbox{row}][\mbox{column}]$$

Example: The matrix

$$ A = \begin{bmatrix} 4 & 0 & -2\\6 & 8 & 1\end{bmatrix} $$
has entries
$$ A[1][1] = 4 \ \ \ \ \ A[1][2] = 0 \ \ \ \ \ A[1][3] = -2 $$
$$ A[2][1] = 6 \ \ \ \ \ A[2][2] = 8 \ \ \ \ \ A[2][3] = 1 $$

- A
*zero matrix*is a matrix where every entry is 0. It can be any size.Example:

$$ \begin{bmatrix} 0 & 0 & 0\\ 0 & 0 & 0\end{bmatrix} \ \ \ \ \ \begin{bmatrix} 0 & 0\\0 & 0\end{bmatrix} \ \ \ \ \ \begin{bmatrix} 0 \\0\end{bmatrix}$$ - An
*identity matrix*is a square matrix where the entries on its*diagonal*are 1 and all other entries are 0. We call these matrices \(I_n\), where \(n\) is the number of rows and columns they have.Example:

$$ I_2 = \begin{bmatrix} 1 & 0\\0 & 1\end{bmatrix} \ \ \ \ I_3 = \begin{bmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \ \ \ \ I_4 = \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 &0\\ 0 & 0 & 1 &0\\0&0&0&1\end{bmatrix}$$

To add two matrices together, just add their like components to make a new matrix of the same size:

Example:

$$
\begin{align*}\begin{bmatrix} 4 & 0 & -2\\1 & 7 & 2\end{bmatrix} + \begin{bmatrix} 6 & 9 & 1\\-4 & 0 & 3\end{bmatrix} &= \begin{bmatrix} 4+6 & 0 + 9 & -2 + 1\\1-4 & 7 + 0 & 2 + 3\end{bmatrix}\\
&= \begin{bmatrix} 10 & 9 & -1\\-3 & 7 & 5\end{bmatrix}
\end{align*}$$

Example:

$$ \begin{bmatrix} 6\\9\end{bmatrix} + \begin{bmatrix} 3 & 0 \\1 & -2\end{bmatrix} \mbox{ is undefined (sizes unequal)}$$

There is only one rule:

The product of a matrix \(A\) and a vector \(v\) is only defined if the number of columns in \(A\) is equal to the number of entries in \(v\).

Example: Neither product below is defined.

$$ \begin{bmatrix} 1 & 2 & 3\\4 & 5 & 6\end{bmatrix} \begin{bmatrix} 14 \\ 20 \end{bmatrix} \ \ \ \ \ \begin{bmatrix} 1 & 2 \\4 & 5 \end{bmatrix} \begin{bmatrix} 14 \\ 20 \\ 15 \end{bmatrix}$$

Example:

$$ \begin{bmatrix} \color{blue}{2} & \color{blue}{0} \\ \color{purple}{-1} & \color{purple}{4} \end{bmatrix} \begin{bmatrix} \color{orange}{3}\\\color{orange}{5} \end{bmatrix} = \begin{bmatrix} \color{blue}{[2,0]} \cdot \color{orange}{[3,5]} \\ \color{purple}{[-1,4]} \cdot \color{orange}{[3,5]} \end{bmatrix}= \begin{bmatrix} (2)(3) + (0)(5) \\ (-1)(3) + (4)(5) \end{bmatrix}= \begin{bmatrix} 6 \\ 17 \end{bmatrix}$$

Example:

$$\begin{align*} \begin{bmatrix} \color{blue}{4} & \color{blue}{-2} & \color{blue}{3} \\ \color{purple}{6} & \color{purple}{3} & \color{purple}{0} \end{bmatrix} \begin{bmatrix} \color{orange}{1}\\\color{orange}{2} \\\color{orange}{3} \end{bmatrix} &= \begin{bmatrix} \color{blue}{[4,-2,3]} \cdot \color{orange}{[1,2,3]} \\ \color{purple}{[6,3,0]} \cdot \color{orange}{[1,2,3]} \end{bmatrix}\\&= \begin{bmatrix} (4)(1)+(-2)(2)+(3)(3) \\ (6)(1)+(3)(2)+(0)(3) \end{bmatrix}= \begin{bmatrix} 9\\ 12\end{bmatrix}
\end{align*}$$

Example:

$$\small{\begin{align*}
\begin{bmatrix} \color{blue}{4} & \color{blue}{-2} & \color{blue}{3} \\ \color{purple}{6} & \color{purple}{3} & \color{purple}{0} \end{bmatrix} \begin{bmatrix} \color{orange}{1} & \color{pink}{5}\\\color{orange}{2} & \color{pink}{0}\\\color{orange}{3} & \color{pink}{-1}\end{bmatrix}
&= \begin{bmatrix} \color{blue}{[4,-2,3]} \cdot \color{orange}{[1,2,3]} & \color{blue}{[4,-2,3]} \cdot \color{pink}{[5,0,-1]} \\ \color{purple}{[6,3,0]} \cdot \color{orange}{[1,2,3]} & \color{purple}{[6,3,0]} \cdot \color{pink}{[5,0,-1]} \end{bmatrix}\\
&= \begin{bmatrix} (4)(1)+(-2)(2)+(3)(3) & (4)(5)+(-2)(0)+(3)(-1)\\ (6)(1)+(3)(2)+(0)(3) & (6)(5)+(3)(0)+(0)(-1)\end{bmatrix}\\
&= \begin{bmatrix} 9 & 17\\ 12& 30\end{bmatrix}
\end{align*}}$$

You've seen functions in algebra classes before, like this one: $$ f(x) = x^2 - 4 $$ This function takes in a number that we call \(x\) until we're ready to specify it. It then squares that number, and then subtracts four.

The result is a new number.

We can imagine the function as

Our example function acts on the number 3, transforming it into the number 5: $$ f(3)= 3^2 - 4 = 9 - 4 =5 $$

When we multiply a vector \(v\) by a matrix \(A\), the result is a new vector.

Sometimes, not much happens.

Example:

$$\scriptsize{\begin{align*}
\begin{bmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \begin{bmatrix} 3 \\4 \\ -2\end{bmatrix} = \begin{bmatrix} 3\\ 4 \\ -2\end{bmatrix}
\end{align*}}$$

But usually, the matrix will transform our vector into an entirely different one.

Example: Let \(v = [1,3]\)

If we multiply \(v\) by the matrix $$ A = \begin{bmatrix} 4 & 0 \\ 0 & 2 \end{bmatrix} $$ we get $$ \begin{bmatrix} 4 & 0 \\ 0 & 2 \end{bmatrix}\begin{bmatrix} 1\\3 \end{bmatrix}=\begin{bmatrix} 4\\6\end{bmatrix}$$

If we multiply \(v\) by the matrix $$ A = \begin{bmatrix} 4 & 0 \\ 0 & 2 \end{bmatrix} $$ we get $$ \begin{bmatrix} 4 & 0 \\ 0 & 2 \end{bmatrix}\begin{bmatrix} 1\\3 \end{bmatrix}=\begin{bmatrix} 4\\6\end{bmatrix}$$

- Stretch the plane horizontally, vertically, or both
- Rotate all points in the plane around the origin
- Reflect the plane across the \(x\) or \(y\) axis
- Shear the plane (makes it slant)
- Project everything in the plane onto a single line through the origin

You don't need to know which matrix does what, but you can try out some transformations

using this applet.

Anything that is an ordered list can be thought of as a vector (since that's all vectors are).

Example: We can represent the RGB color (90, 150, 200) as the vector

$$ \begin{bmatrix} \color{red}{90} \\ \color{green}{150} \\ \color{blue}{200}\end{bmatrix} $$ which is a nice light blue:

$$ \begin{bmatrix} \color{red}{90} \\ \color{green}{150} \\ \color{blue}{200}\end{bmatrix} $$ which is a nice light blue:

- Every pixel in an image on a screen has an RGB color vector
- If we want to adjust the color of an image, we do so by changing each pixel
- Once we find a matrix that represents the adjustment we're looking for, we just have to multiply the vector of each pixel by the same matrix
- After that, every pixel is adjusted in the same way

This is the process we go through to adjust the color of an image, whether it's enhancing the green, toning down the blue, increasing contrast, brightening the entire picture, or adding a color filter such as sepia or black & white.

- Most current smartphones have a 12 megapixel sensor, meaning they take images with 12
*million*pixels, each represented by a vector [R, G, B] - To adjust an image, we'll need to multiply each one by a \(3 \times 3\) matrix.
- To find just one of those matrix/vector products requires 9 dot products.
- Each dot product requires three products and two sums.
- That's 27 products and 18 sums
*per pixel*. - If we wanted to work all of this out by hand, we'd need to find:
- 324,000,000 products of two numbers, and
- 216,000,000 sums of two numbers

That's *540,000,000* operations every time we adjust the image!

If the matrix has decimals in it, our new color vector will too, so we may also need to round.

$$\begin{bmatrix} 2 & 0 & 0 \\ 0 & 2.1 & 0 \\ 0 & 0 & -1 \end{bmatrix}\begin{bmatrix}200 \\ 50 \\ 10 \end{bmatrix} = \begin{bmatrix}\color{red}{400} \\ 100.5 \\ \color{red}{-1} \end{bmatrix}= \begin{bmatrix}255 \\ 101 \\ 0\end{bmatrix}$$

Some photo editors use other schemes for this problem, but this is not an unusual method of handling values outside the possible range.When you change the matrix, you'll see how the colors are affected.

While it's good to know matrices

For example, we might know that matrices can be used to rotate a figure, but how to we find just the right matrix? In other words, how do we find the function we need to use to get the effect we want?

Next week, we'll see how to find functions as matrices that help us do what we need to.

Example: Find an equation of the line that passes through the point \((2,3)\) and has slope 5.

Since we know a point \((x_1,y_1)\) on our line, and we know the slope \(m\), we can use the point slope form of the line: $$ y - y_1 = m(x-x_1) $$ which gives us $$ y - 3 = 5(x - 2)$$ This is a perfectly valid equation, but we can solve for \(y\) if you prefer slope intercept form: $$ y = 5x - 7$$

Since we know a point \((x_1,y_1)\) on our line, and we know the slope \(m\), we can use the point slope form of the line: $$ y - y_1 = m(x-x_1) $$ which gives us $$ y - 3 = 5(x - 2)$$ This is a perfectly valid equation, but we can solve for \(y\) if you prefer slope intercept form: $$ y = 5x - 7$$

Example: Find the equation of a parabola that has roots (x-intercepts) at \(x=3\) and \(x=-1\).

If the parabola has a root at \(x=3\), then it must have a factor of \((x-3)\). Similarly, it must also have a factor of \((x+1)\). So our equation would be $$ y = (x-3)(x+1) = x^2-2x-2 $$ If we multiply our formula by any number, we'll still have a parabola with those roots, such as $$y = 5(x-3)(x+1) = 5x^2-10x-10 $$ We'd need more information, like a point on the graph, to specify which parabola we want.

If the parabola has a root at \(x=3\), then it must have a factor of \((x-3)\). Similarly, it must also have a factor of \((x+1)\). So our equation would be $$ y = (x-3)(x+1) = x^2-2x-2 $$ If we multiply our formula by any number, we'll still have a parabola with those roots, such as $$y = 5(x-3)(x+1) = 5x^2-10x-10 $$ We'd need more information, like a point on the graph, to specify which parabola we want.

Example: Find a matrix that stretches an image horizontally by a factor of 3.

Example: Find a matrix that rotates an image by 90 degrees.

Example: Find a matrix that removes all shades of red from an image.