VM PDF
VM PDF
Sugih Jamin
EECS 487
Winter 2010
Vectors and Matrices
1. Vectors
A vector is an object with magnitude and direction (velocity, force, acceleration, etc).
A scalar is an object with just magnitude (temperature, pressure, age, length). A vector,
denoted ~v or v, has no initial point and is often best thought of as at the origin. A vector may
be written in component form ~v = hv1 , v2 , v3 i (in three dimensions) but it is important to
remember that the components are dependent on the coordinate system in use. The vector
as a whole is a real object; the components are a tool. One special vector to keep in mind is
the zero (or null) vector ~0 whose components are all zero (in every coordinate system).
The length, norm, or magnitude of a vector is given by
q
||~v || = v12 + v22 + v32
and sometimes denoted |~v |.
Some properties to keep in mind about vectors are (given vectors ~a, ~b, and ~c and scalars
c and d):
1) ~a + ~b = ~b + ~a (Commutative property)
2) (~a + ~b) + ~c = ~a + (~b + ~c) (Associative property)
3) ~a + ~0 = ~a (Additive identity property)
4) ~a + (−~a) = ~0 (Additive inverse property)
5) c(d~a) = (cd)~a (Associativity with Scalars)
6) (c + d)~a = c~a + d~a (Distributive property)
1
7) c(~a + ~b) = c~a + d~b (Distributive property)
8) 1(~a) = ~a (Multiplicative identity property)
9) 0(~a) = ~0
Given a vector ~v the unit vector, or normal vector, in the direction of ~v , denoted v̂ is
given by
~v
v̂ = .
||~v ||
The vector v̂ is parallel to ~v meaning that v̂ = t~v where t is a scalar with t = 1/||~v ||.
There are three standard unit vectors in Cartesian coordinates: ı̂ = h1, 0, 0i, ̂ = h0, 1, 0i,
and k̂ = h0, 0, 1i. Thus the vector ~u = hu1 , u2 , u3 i in Cartesian coordinates can be written
~u = u1 ı̂ + u2 ̂ + u3 k̂.
Two vectors are equal if and only if (abbreviated iff) they have the same magnitude and
the same direction; in other words, each of their respective components is equal.
Two nonzero vectors ~u and ~v are parallel if there exists a scalar c such that ~u = c~v .
2
Given a triangle with sides of lengths a, b, and c and with angle θ opposite side c
Using properties of the dot product, the left side can be rewritten
||~a − ~b||2 = (~a − ~b) · (~a − ~b) = (~a − ~b) · ~a − (~a − ~b) · ~b
= ~a · ~a − ~b · ~a − ~a · ~b + ~b · ~b = ||~a||2 + ||~b||2 − 2~a · ~b.
as an alternate form of the dot product. This can also be used to find the angle θ between
two vectors ~a and ~b.
~a · ~b
cos θ =
||~a|| ||~b||
3
Let ~a and ~b be two nonzero vectors separated by an angle θ.
The vector ~b can be split into two components: one that is parallel to ~a and one that is
orthogonal to it. The component of ~b parallel to ~a is called the projection of ~b onto ~a or
the vector component of ~b along ~a and is denoted proj~a~b. Notice that
||proj~a~b|| = ||~b|| cos θ
and the direction is along the unit vector â. That gives
! !
~
~
~
~a ||~a|| ||~b|| cos θ ~a ~a · ~b
proj~a b = ||b|| cos θ â = ||b|| cos θ = = ~a = (â · ~b)â.
||~a|| ||~a|| ||~a|| ||~a||2
Observe also that !
~a · ~b
proj~a~b = ~a = t~a
~a · ~a
where t is a scalar and t = (~a · ~b)/||~a||2 . Thus proj~a~b is always parallel to ~a.
The component of ~b orthogonal to ~a is then just
!
~a · ~b
proj~a⊥~b = ~b − proj~a~b = ~b − ~a.
||~a||2
Be aware that there is no standard notation for the orthogonal component of one vector with
respect to another and proj~a⊥~b was used for illustration.
The projection of ~b along ~a and the perpendicular projection decompose ~b which means
that ~b = proj~a~b + proj~a⊥~b, which is trivially true by the construction of proj~a⊥~b. Also proj~a~b
and proj~a⊥~b are orthogonal, shown as follows
" ! # " ! #
~a · ~b ~a · ~b
proj~a~b · proj~a⊥~b = ~a · ~b − ~a
||~a||2 ||~a||2
" ! # " ! # " ! #
~a · ~b ~a · ~b ~a · ~b
= ~a · ~b − ~a · ~a
||~a||2 ||~a||2 ||~a||2
!2
(~a · ~b)2 ~a · ~b (~a · ~b)2 (~a · ~b)2
= − (~
a · ~
a ) = − ||~a||2 = 0.
||~a||2 ||~a||2 ||~a||2 ||~a||4
4
There are two edge cases of projection:
1) If ~a = ~b then the component of ~b along ~a is ~a itself. Restated it says that iff ~a = ~b
then
!
~a · ~b
~a · ~a
||~a||2
~
proj~a b = ~a = ~a = ~a = ~a
||~a||2 ||~a||2 ||~a||2
~b can be broken up into two components. One parallel to ~a and one orthogonal. They
trivially add up to make ~b.
! " ! #
~b = proj~a~b + proj⊥~b = ~a · ~b ~a · ~b
~a ~a + ~b − ~a
||~a||2 ||~a||2
The vector in the same plane as ~a and ~b (any two nonzero vectors form a plane) with
angle θ with respect to ~a (instead of π − θ) is called the reflection of ~b across ~a, sometimes
denoted ref~a~b. This vector has the same orthogonal component to ~a as ~b does, but that its
parallel component is flipped. That means
! " ! # !
~a · ~b ~a · ~b ~a · ~b
ref~a~b = (−1) ~a + ~b − ~a = ~b − 2 ~a = ~b − 2(â · ~b)â.
||~a||2 ||~a||2 ||~a||2
Sometimes reflection is used to mean mirroring vector ~b along ~a instead of the use above
where it is based off a ray reflecting off a surface. In such a context the ray produced will
be the negative of the one derived above.
5
3. The Cross Product
The cross product between two vectors ~u = hu1 , u2 , u3 i and ~v = hv1 , v2 , v3 i is defined as
~u × ~v = (u2 v3 − u3 v2 ), (u3 v1 − u1 v3 ), (u1 v2 − u2 v1 ) .
Unlike the dot product the cross product produces a vector and not a scalar. It can be
remembered using a trick with determinants (which will be reviewed later):
ı̂ ̂ k̂
~u × ~v = u1 u2 u3 = (u2 v3 − u3 v2 )ı̂ + (u3 v1 − u1 v3 )̂ + (u1 v2 − u2 v1 )ẑ.
v1 v2 v3
The cross product is not defined in 2D and if one wishes to use it with two 2D vectors,
set them to have a third component equal to zero and proceed. Thus given ~u = hu1 , u2 i and
~v = hv1 , v2 i,
~u × ~v = hu1 , u2 , 0i × hv1 , v2 , 0i = h0, 0, u1 v2 − u2 v1 i.
Some properties of the cross product (given vectors ~u, ~v and w
~ and scalar c) are:
1) ~u × ~v = −(~v × ~u) (Anti-commutative property)
2) ~u × (~v + w) ~ = (~u × ~v ) + (~u × w)~ (Distributive property)
3) c(~u × ~v ) = (c~u) × ~v = ~u × (c~v )
4) 0 × ~v = ~0
5) ~v × ~v = ~0
6) ~u · (~v × w)
~ = (~u × ~v ) · w
~
7) ~u × ~v × w ~ = (~u · w)~
~ v − (~u · ~v )w
~
The cross product ~u ×~v is orthogonal to both ~u and ~v . That is (~u ×~v ) ·~u = (~u ×~v ) ·~v = 0.
Also, ~u × ~v = 0 iff ~u = c~v for some scalar c, meaning that they are parallel.
Notice that
p
||~u × ~v || = (u2 v3 − u3 v2 )2 + (u3 v1 − u1 v3 )2 + (u1 v2 − u2 v1 )2
q
= (u21 + u22 + u23 )(v12 + v22 + v32 ) − (u1 v1 + u2 v2 + u3 v3 )2
p
= ||~u||2 ||~v ||2 − (~u · ~v )2
s
(~u · ~v )2
= ||~u|| ||~v || 1 −
||~u||2 ||~v ||2
√
= ||~u|| ||~v || 1 − cos2 θ
||~u × ~v || = ||~u|| ||~v || sin θ.
6
Let ~u and ~v be the two sides of a parallelogram.
7
4. Basis
The set of all real numbers is often denoted R. The set of all points in 3D space is written
R3 (the Cartesian product R × R × R) and any point in it can be written as (x, y, z) with
x, y, z ∈ R; however, the components x, y, and z are dependent on the given basis.
Given a vector space V (the definition of which is not important here) a set of vectors
~v1 , ~v2 , . . . , ~vn is said to span V iff for all vectors ~a ∈ V there exists c1 , c2 , . . . , cn ∈ R such
that ~a = c1~v1 + c2~v2 + . . . + cn~vn .
A basis for a vector space V is a set of vectors {~v1 , . . . , ~vn } that span V and are linearly
independent, that is to say that no vector in the set is a linear combination of the others.
A basis is an orthogonal basis iff all basis elements are mutually orthogonal. That is,
given a basis {~vn } for V , one has that ~vi · ~vj = 0 when i 6= j. A basis is said to be a normal
basis if each element has unit length (magnitude). A basis is said to be an orthonormal
basis when it is both normal and orthogonal.
ı̂ × ̂ = k̂
̂ × k̂ = ı̂
k̂ × ı̂ = ̂
̂ × ı̂ = k̂
k̂ × ̂ = ı̂
ı̂ × k̂ = ̂.
8
The vector ~v = αr̂ + β θ̂ + γ φ̂ would be written (α, β, γ) and the vector ~u = αx̂ + β ŷ + γ ẑ
would also be written (α, β, γ). Thus it is extremely important to know what basis is being
used. Remember that a vector with its magnitude (length) and direction (sense) is the real
object and that the components are just a basis-dependent representation.
Given a basis ~v1 , ~v2 , and ~v3 (in the 3-dimension case) and a vector ~u the direction
angles are defined as the angles between the vector and each coordinate axis. They are
usually written α, β, and γ where α =(the angle between ~u and coordinate axis ~v1 ). β and
γ are the angles for the other two coordinate axes. The direction cosines are defined as
the cosines of the direction angles. That is
cos α = û · v̂1
cos β = û · v̂2
cos γ = û · v̂3 .
A ray is simply a vector with a specified initial point. It can also be thought of as a line
with t ≥ 0 (it has one endpoint, a line segment has two).
A plane containing the point (x0 , y0 , z0 ) and having a normal vector (it is orthogonal to
the plane) ~n = hA, B, Ci is given by
A(x − x0 ) + B(y − y0 ) + C(z − z0 ) = 0
or by letting D = −(Ax0 + By0 + Cz0 ),
Ax + By + Cz + D = 0.
The angle θ between two planes with normal vectors ~n0 and ~n2 is given by
|~n0 · ~n1 |
cos θ = .
||~n0 || ||~n1 ||
This is a direct application of the angle between two vectors. The numerator has absolute
value since one of the planes could be “upside-down” and the angle between two planes must
be between 0 and π/2 inclusively.
9
The angle between a vector ~v and a plane with normal ~n is just cos (π/2 − θ) = |v̂ · n̂|.
Let ~n be the normal of a plane containing the point P and let Q be a point not in the
plane.
Let ~u be the direction vector of a line containing the point P and let Q be a point not
on the line. By similar arguments as above the distance d between the point Q and the line
is
−→
−→ ||P Q × ~u||
d = ||P Q|| sin θ =
||~u||
−→
where θ is the angle between P Q and ~u.
6. Matrices
A matrix, denoted M̂ along with many other notations, is a rectangular array of numbers
for instance
3 −8 16
M̂ = .
6 1 −9
This particular matrix is of order 2 × 3, always listing the number of rows first. A matrix
with equal number of rows and columns is called a square matrix.
10
A vector is simply a matrix with only one column. Vectors are often written as matrices
with one row but this is merely for convenience and is incorrect. Thus a vector ~v = hv1 , v2 , v3 i
is the same as
v1
~v = v2 .
v3
7. Matrix Multiplication
The multiplication of two matrices is analogous to the dot product. Given vectors ~u =
hu1 , u2 , u3 i and ~v = hv1 , v2 , v3 i we can think of their dot product as multiplying the transpose
of one by the other. That is
T
u1 v1 v1
~u · ~v = u2 v2 = u1 u2 u3 v2 = (u1 v1 + u2 v2 + u3 v3 ).
u3 v3 v3
Think of taking the dot product with a row and a column. In the product ÂB̂, the element
at row i and column j will be the “dot product” of row i in matrix  with column j in
matrix B̂. An example should help to illustrate the point.
1 2 5 6 ? ?
=
3 1 7 4 ? ?
The element at row 1 and column 1 of the product will be row 1 in the left matrix dot
column 1 in the right matrix.
1 2 5 6 1(5) + 2(7) ?
=
3 1 7 4 ? ?
The element at row 1 and column 2 of the product will be row 1 in the left matrix dot
column 2 in the right matrix.
1 2 5 6 19 1(6) + 2(4)
=
3 1 7 4 ? ?
The element at row 2 and column 1 of the product will be row 2 in the left matrix dot
column 1 in the right matrix.
1 2 5 6 19 14
=
3 1 7 4 3(5) + 1(7) ?
11
The element at row 2 and column 2 of the product will be row 2 in the left matrix dot
column 2 in the right matrix.
1 2 5 6 19 14
=
3 1 7 4 22 3(6) + 1(4)
1 2 5 6 19 14
=
3 1 7 4 22 22
Matrix multiplication is only possible if the first matrix’s number of columns is equal to
the second matrix’s number of rows.
The identity matrix is the matrix Iˆ such that for any square matrix M̂ it follows that
M̂ I = IˆM̂ = M̂ . The identity matrix must be the same size as M̂ and has ones on the main
ˆ
diagonal and zeros elsewhere. For a square matrix of size three one has
15 8 1 1 0 0 15 8 1
0 3 −9 0 1 0 = 0 3 −9
−7 −4 2 0 0 1 −7 −4 2
and thus for order three
1 0 0
Iˆ = 0 1 0 .
0 0 1
The minor (i, j) of a matrix M̂ , denoted M̂i,j , is the determinant of the matrix made
by removing row i and column j from M̂ .
a b a b
= |c| = c
For example: M̂1,2 of is
c d c d
The determinant of any square matrix is obtained by taking any row (or column) and
summing the product of each element of that row (or column) with its cofactor.
12
a b
The determinant of a square 2 × 2 matrix M̂ = is then by (using the first
c d
row)
|M̂ | = a Ĉ1,1 + b Ĉ1,2 = a(−1)1+1 M̂1,1 + b(−1)1+2 M̂1,2 = ad − bc.
It is worth nothing that choosing to use the second row or either of the columns would still
result in ad − bc, the difference of the diagonals.
a b c
The determinant of a 3 × 3 matrix M̂ = d e f is then (using the first row)
g h i
a b c a b c a b c a b c
d e f = a(−1)1+1 d e f + b(−1)1+2 d e f + c(−1)1+3 d e f
g h i g h i g h i g h i
e f d f d e
= a
− b
+ c
= a(ei − hf ) − b(di − gf ) + c(dh − ge)
h i g i g h
a b c
d e f = aei − ahf − bdi + bgf + cdh − cge
g h i
This result would have been obtained using any row or column. A trick to taking deter-
minants is to think of minors instead of cofactors. Work along any row or column summing
the product of each element with its minor and using signs as follows.
+ − + ...
− + − ...
+ − + ...
.. .. .. . .
. . . .
8. Inverse of a Matrix
If a matrix is not square the notion of an inverse is vacuous. For any square matrix M̂
there exists an inverse M̂ −1 such that M̂ M̂ −1 = M̂ −1 M̂ = Iˆ if and only if |M̂ | 6= 0 (an
invertible matrix is also called non-singular).
There are two common ways to find the inverse of a matrix. The first is called Cramer’s
rule and the second is Gauss-Jordan elimination.
The cofactor matrix of a matrix M̂ , denoted Ĉi,j without substituting numbers in for
i and j, is the matrix where every element ai,j is the cofactor Ĉi,j of M̂ .
13
Cramer’s rule states that given a square matrix M̂ with |M̂ | =
6 0
1
M̂ −1 = Adj(M̂ ).
|M̂ |
a b
As an example take the matrix M̂ = . The cofactors are Ĉ1,1 = d, Ĉ1,2 = −c,
c d
d −c
Ĉ2,1 = −b, and Ĉ2,2 = a. Thus the cofactor matrix is and the adjugate is merely
−b a
the transpose of that, hence
d −b
Adj(M̂ ) = .
−c a
Thus Cramer’s rule states that
−b
d
−1 1 d −b ad−bc ad−bc
M̂ = = −c a
ad − bc −c a ad−bc ad−bc
1 0
which when either left- or right-multiplied by M̂ does indeed produce the identity
0 1
matrix (of order 2).
The inverse of a matrix can be found by cleverly applying these elementary operations
to a matrix M̂ augmented with the identity matrix (that means placing them side-by-side
to make a larger matrix). Remember that a matrix must be square to have an inverse in the
first place so it makes sense to be able to place it along side the identity matrix. This may
sound confusing but an simple example should be illustrious. Given the matrix
a b
M̂ =
c d
the inverse will be found as follows.
14
Elementary row operations must be performed in order to make the matrix on the “left” look
like the identity matrix. Thus where the a is should be a 1. So the first row is multiplied by
1/a.
1 b/a 1/a 0
c d 0 1
Where the c is should be a 0, so add −c times the first row to the second row.
1 b/a 1/a 0
c + (−c) d + (−c)b/a 0 + (−c)1/a 1
1 b/a 1/a 0
0 d − bc/a −c/a 1
The entry “d − bc/a” should be a 1 so we multiply the second row by 1/(d − bc/a).
1 b/a 1/a 0
−c/a 1
0 1 d−bc/a d−bc/a
1 b/a 1/a 0
−c a
0 1 ad−bc ad−bc
All that remains is to change the “b/a” to 0. So add the second row times (−b/a) to the
first.
−c a
1 0 1/a + (−b/a) ad−bc 0 + (−b/a) ad−bc
−c a
0 1 ad−bc ad−bc
cb/a −b
1 0 1/a + ad−bc ad−bc
−c a
0 1 ad−bc ad−bc
ad−bc cb −b
1 0 a(ad−bc) + a(ad−bc) ad−bc
−c a
0 1 ad−bc ad−bc
d −b
1 0 ad−bc ad−bc
−c a
0 1 ad−bc ad−bc
After using elementary row operations on the augmented matrix, the left side (which
was M̂ ) is now the identity matrix and the right side (which was the identity matrix) is now
M̂ −1 . This matrix is exactly the inverse of M̂ found using Cramer’s rule.
Gauss-Jordan Elimination is done (to the augmented matrix of M̂ and the identity ma-
trix) as
1) Use row swaps to make the first row have a nonzero leading coefficient.
2) Divide the first row by its leading coefficient to make the leading coefficient 1 or swap
in a row that already has it.
3) Add multiples of the first row to all other rows to make each row have a zero in the
first column.
4) Repeat the process with the second row and so forth.
15
Here is a simple example to show it once more. Here the inverse of
2 3 1
1 0 2
4 1 2
will be found.
The determinant is 15 (which is not zero) so the matrix has an inverse and so one proceeds
as follows.
2 3 1 1 0 0
1 0 2 0 1 0
4 1 2 0 0 1
Swap the first and second rows to put a 1 in place (this is easier than doing division to get
it).
1 0 2 0 1 0
2 3 1 1 0 0
4 1 2 0 0 1
Swap the second and third rows (or do a division if preferred) to put a 1 as the leading
coefficient in the second row.
1 0 2 0 1 0
0 1 −6 0 −4 1
0 3 −3 1 −2 0
16
Divide the third row by 15.
1 0 2 0 1 0
0 1 −6 0 −4 1
0 0 1 1/15 2/3 −1/5
Add (-2) times the third row to the first.
1 0 0 −2/15 −1/3 2/5
0 1 −6 0 −4 1
0 0 1 1/15 2/3 −1/5
Add (6) times the third row to the second.
1 0 0 −2/15 −1/3 2/5
0 1 0 2/5 0 −1/5
0 0 1 1/15 2/3 −1/5
Thus the matrix on the right is the inverse of the matrix above.
10. System of Linear Equations
Given two equations ax + by = c and dx + ey = f one can write this as
a b x c
= .
d e y f
This is because equality of matrices is equality of all components, so multiplying the above
out results in the original two equations. One can then apply
−1
a b
d e
to both sides to find x and y.
11. Wrap-up
So how much should you take away from all of this? You should be able to take the dot
product, cross product, or direct product of vectors; you should be able to find the distance
between points and lines or points and planes; you should be able to find the reflection of one
vector off another; you should be able to multiply any two matrices, find the determinant
of one, or the inverse; and if asked you should be able to prove any of the simple identities
such as ~u · (~v × w)
~ = (~u × ~v ) · w.
~
It may be in your favor to practice some of the above skills. The mental overhead of
computer graphics can be greatly lowered if working with vectors and matrices is second
nature!
Transformations and rotations will be covered in later notes.
17