# Chapter 9: Matrix Operations

## Simple Operations

### Scalar Multiplication

Simply multiply each element by the scalar.

### Linear Combination

Not surprisingly, a linear combination of matrices is a matrix of the form:

### Transpose

To find the transpose of a matrix $A$, with notation $A^T$, interchange rows and columns of matrix $A$.

A symmetric matrix is identical to its tranpose. Only a square matrix can be symmetric.

## Vector Operations

### Dot Product

The dot product of two vectors $v$ and $w$ is the sum of each of their corresponding elements.

Note that this operation takes two vectors and returns a scalar.

### Normalization

The dot product of a vector with itself is the sum of the squares of its elements.

We can use this to compute a vector’s length.

### Unit Vectors

A unit vector is one with length = 1

Unit vectors are useful and we sometimes need to take an arbitrary vector $\vec v$ and normalize is to make it have unit length. This often occurs when we care about the direction of a vector, but not its magnitude.

Note the different symbol used here to denote a unit vector $\hat v$, as opposed to $\vec v$.

### Angles

We’ve seen how the dot product of a vector with itself relates to the length of the vector.

The dot product of a vector with another vector relates to the length of both vectors, as well as the angle between them.

Specifically:

Where $\theta$ is the angle between the two vectors.

When using normalized vectors:

Thus the convenience of normalized vectors is discovered.

This is one of the most useful formulas used in graphics. It is commonly used to compute the angle between two vectors, i.e.

We can use this to determine if two vectors are pointing away from one another or not.

### Projection

The projection of a vector $\vec a$ onto vector $\vec b$ is:

## Matrix Multiplication

### By Vectors

A common use of matrix multiplication in computer graphics is to multiply a matrix times a vector.

For a given matrix $A$ and vector $v$, we say for $A * v$ that the column vector $v$ is pre-multiplied by $A$.

Note that the number of rows of $A$ must be the number of elements in $v$.

The result of $A * v$ is a column vector $c$ whose $i^{th}$ element is the dot product of the $i^{th}$ row of $A$ with $v$.

### By Matrices

Matrix by matrix multiplication $A * B$ is only defined when the number of columns in $A$ is the number of rows in $B$.

Can we multiply $3 \times 2$ with $2 \times 4$? Yes

Can we multiply $2 \times 3$ with $2 \times 4$? No

Note that multiplying a matrix by the identity matrix produces the original matrix.

Note that matrix multiplication is not commutative.

 A * B \ne B * A \$4