# Lecture 7: 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 , with notation , interchange rows and columns of matrix .

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 and 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 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 , as opposed to .

### 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 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 onto vector 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 and vector , we say for that the column vector is pre-multiplied by .

Note that the number of rows of must be the number of elements in .

The result of is a column vector whose element is the dot product of the row of with .

### By Matrices

Matrix by matrix multiplication is only defined when the number of columns in is the number of rows in .

Can we multiply with ? **Yes**

Can we multiply with ? **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