Computation Methods
Computation Methods
3
4 CONTENTS
3 Representing Rotation 45
3.1 Rotation Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.2 Properties of Rotation Matrices . . . . . . . . . . . . . . . . . . . 45
3.3 Exponential Map . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.4 Euler Angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.5 Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.5.1 Structure of Quaternions . . . . . . . . . . . . . . . . . . 51
3.5.2 Unit Quaternions . . . . . . . . . . . . . . . . . . . . . . . 52
3.5.3 Interpolation of Quaternioins . . . . . . . . . . . . . . . . 54
4 Introduction to Optimization 59
4.1 Di↵erential Calculus . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.2 Unconstrained Optimization . . . . . . . . . . . . . . . . . . . . . 60
4.2.1 Conditions for local minima . . . . . . . . . . . . . . . . . 61
4.2.2 Gradient method . . . . . . . . . . . . . . . . . . . . . . . 62
4.2.3 Steepest descent method . . . . . . . . . . . . . . . . . . . 63
CONTENTS 5
Denote the set of real numbers by R, and the set of n vectors with real compo-
nents by Rn .
1.1.2 Properties
The vector space with the operations of a vector addition and a scalar multipli-
cation holds the following properties:
1. commutative : a + b = b + a
2. associative : (a + b) + c = a + (b + c)
7
8 CHAPTER 1. REVIEW ON LINEAR ALGEBRA
4. distributive: ↵(a + b) = ↵a + ↵b
, where a, b, c 2 Rn , ↵ 2 R.
1.1.4 Subspace
3. Let 2 3
1 0 ··· 0
6 7
h i 6 7
60 1 ··· 07
I n = e 1 , · · · , en =6
6 .. .. ..
7
.. 7 ,
6. . . .7
4 5
0 0 ··· 1
det In = 1.
x1 a1 + x2 a2 + · · · xn an = b,
Ax = b,
where x = [x1 , x2 , · · · , xn ]T .
Theorem 1. The system of equations Ax = b has a solution if, and only if,
holds. Furthermore, equality holds if, and only if, x = ↵y for some ↵ 2 R.
12 CHAPTER 1. REVIEW ON LINEAR ALGEBRA
1.2 Transformations
If one chooses natural bases for Rn and Rm , then the linear operator L can
be represented by a matrix A as
L(x) = Ax.
Let {e1 , e2 , · · · , en } and {e01 , e02 , · · · , e0n } be two bases for Rn and the matrix
T relate these bases as follows:
2 3 1 2 3
p p p p p p
6 7 6 7
6 0 7 6 7
T = 6e1 e02 · · · e0n 7 6e1 e2 ··· en 7 .
4 5 4 5
p p p p p p
1
A=T BT.
1.2. TRANSFORMATIONS 13
( ) , det( I A) = 0.
The roots of the characteristic polynomial, i and their associated vectors vi are
called eigenvalues and eigenvectors, respectively.
1
V AV = diag{ 1, 2, · · · , n },
h p p p
i
where V = v1 v2 ··· vn .
p p p
Note that all matrix can not be diagonalized. If the eigenvalues are not all
distinct, we may find only m(< n) distinct eigenvectors.
-
Px
x = x1 + x2 ,
where x1 2 V, x2 2 V ? .
Px 2 V and x P x 2 V ?.
R(A) = Ax | x 2 Rn
N (A) = x 2 Rn | Ax = 0 .
f (x) = xT Qx,
1u1
v2
A
v1 2u2
Let us discuss the geometric meaning of SVD. Using the singular value de-
composition, a matrix A can be represented as
X
T
A= i ui v i .
i
Problem Set
1. Suppose that {v1 , v2 , · · · , vn } is a basis for Rn . Show that if A is an n ⇥ n
invertible matrix, then {Av1 , Av2 , · · · , Avn } is also a basis for Rn .
A1 = {[1, 1, 1]T , [1, 1, 0]T , [1, 0, 0]T }, B1 = {[0, 1]T , [1, 2]T }
A2 = {[2, 1, 3]T , [1, 0, 2]T , [0, 1, 0]T }, B2 = {[1, 1]T , [2, 1]T }
X1
1 n
eA = A .
n=0
n!
[ Note: Recall that the Taylor series expansion of the exponential function
P1 n
gives us ex = n=0 xn! for x 2 R. Hence we can regard the above defini-
tion as a matrix version of the exponential function. In this problem, we
assume that A is real and symmetric. However the above definition and
property hold for an arbitrary square matrix.]
10. Find directions of principal axes and their magnitude of the ellipse
5x2 4xy + 8y 2 = 1.
Chapter 2
It is called the Gaussian elimination procedure. For the system with a full
rank matrix A, a solution can be computed efficiently by the back-substitution
procedure.
1 ⇣ 0 ⌘
n
X
xi = b a0ij xj , i = n, · · · , 1.
a0ii i j=i+1
Note that the above back-substitution holds only when the diagonal entries a0ii
are not zero.
19
20 CHAPTER 2. SOLVING LINEAR SYSTEM
for i = n:1 do
x(i) = b(i)
for j = i+1:n do
x(i) = x(i) - a(i,j) * x(j)
end
x(i) = x(i) / a(i,i)
end
Algorithm 1: Back-substitution
A b x
, where A 2 Rm⇥n .
@f (x)
= 2(AT Ax AT b) = 0,
@x
x̃ = (AT A) 1
b.
xT AT (Ax b) = 0
xT (AT Ax AT b) = 0 , 8x 6= 0,
x = (AT A) 1
b.
(x xm )T xm = (x xm )T AT (AAT ) 1
b
= 0.
22 CHAPTER 2. SOLVING LINEAR SYSTEM
Therefore
kxk2 = kx xm + xm k2
= kx xm k2 + kxm k2 + 2(x xm ) T xm
= kx xm k2 + kxm k2 kxm k2 .
In general, when we may have rank(A) < min(m, n) – in other words, A may
be rank-deficient – we seek the minimum norm least squares solution x which
minimizes both ||x||2 and ||b Ax||2 .
kAxk
kAk2 , maxn .
x2R kxk
x6=0
Now let us consider how the perturbation of b a↵ects the change of solution
x by comparing Ax = b with A(x + x) = b + b.
1
x=A b , b = Ax
1
k xk kA kk bk , kbk kAkkxk
k xk k bk max k bk
) kA 1
kkAk = .
kxk kbk min kbk
max
cond(A) = .
min
1
x=A Ax
1 k Ak
k xk kA kk Akkxk = cond(A) kxk
kAk
k xk k Ak
cond(A) .
kxk kAk
2.2.1 LU factorization
Ln 1 Ln 2 · · · L1 A = U
For a general n ⇥ n matrix, let xk denote the kth column of the matrix at
the beginning of step k. Then Lk can be chosen such that it transforms all the
entries below the (k + 1)th element of xk to be zero.
2 32 3 2 3
1 x1k x1k
6 76 . 7 6 . 7
6 .. 76 . 7 6 . 7
6 . 76 . 7 6 . 7
6 76 7 6 7
6 76 7 6 7
6 1 7 6 xkk 7 6xkk 7
Lk xk = 6
6
76
76
7=6
7 6
7,
7
6 lk+1,k 1 7 6xk+1,k 7 6 0 7
6 76 7 6 7
6 .. .. 76 . 7 6 . 7
6 . . 7 6 .. 7 6 .. 7
4 54 5 4 5
lnk 1 xnk 0
where
xjk
ljk = .
xkk
Lemma 5. Let lk = [0, · · · , 0, lk+1,k , · · · , lnk ]T . Then
Lk = I lk eTk
Lk 1 = I + lk eTk
Lk 1 Lk+1
1
= I + lk eTk + lk+1 eTk+1 .
2.2. DIRECT APPROACH 25
initialization: U = A, L = I
for k = 1 : n 1 do
for j = k + 1 : n do
l(j, k) = u(j, k)/ u(k, k)
u(j, k : n) = u(j, k : n) l(j, k) ⇤ u(k, k : n)
end
end
Algorithm 2: LU factorization
1. Solve Ly = b. (forward-substitution)
2. Solve U x = y. (back-substitution)
Consider a case when akk is near to zero. Obviously it may induce a large
round-o↵ error because the Gaussian elimination requires a division of elements
by akk . But there is no inherent reason to eliminate against the kth row. We
introduce a permutation matrix P which is simply an identity matrix with its
rows or columns permuted. A permutation matrix is useful to permute rows or
columns of a matrix.
h1 0 0i
For example, if P = 001 , P A is A with the second and third rows per-
010
muted and AP is A with second and third columns permuted. Note that a
permutation matrix is not symmetric in general.
26 CHAPTER 2. SOLVING LINEAR SYSTEM
Ln 1 Pn 1 · · · L 2 P2 L 1 P1 A = U
where L0k = Pn 1 · · · Pk+1 Lk Pk+1 · · · Pn 1. Note that L0k has the same structure
as Lk , that is, L0k is simply Lk with non trivial entries permuted. This property
is important because it makes L0n 1 · · · L01 lower triangular.
Finally we have
P A = LU,
1 1 1
where L = L0 1 L0 2 · · · L0 n 1 and P = Pn 1 · · · P2 P1 . This process is called
the partial pivoting and one of the most popular criteria to choose the pivot is
to find the largest entries from xk .
1 1 1 1 1 1 1
(A + U CV ) =A A U (C +VA U) VA ,
2.2. DIRECT APPROACH 27
initialization: U = A, L = I, P = I
for k = 1 : n 1 do
select i k maximizing |u(i, k)|
u(k, k : n) u(i, k : n)
l(k, 1 : k 1) l(i, 1 : k 1)
p(k, :) p(i, :)
for j = k + 1 : n do
l(j, k) = u(j, k)/ u(k, k)
u(j, k : n) = u(j, k : n) l(j, k) ⇤ u(k, k : n)
end
end
Algorithm 3: LU factorization with partial pivoting
x = (A + uv T ) 1
b
1 1 1
=A b A uv T A 1
b
1 + hv, A 1 ui
1 hv, A 1 bi 1
=A b A u.
1 + hv, A 1 ui
Note that we don’t need an explicit inversion of (A + uv T ) to solve the modified
problem.
Theorem 11. If A is real and positive definite, then there exists a unique
factorization of A = RT R, where R is an upper triangular matrix with strictly
positive diagonal entries. It is called the Cholesky factorization.
28 CHAPTER 2. SOLVING LINEAR SYSTEM
= R1T A1 R1 ,
p 1 T
where ↵ = a11 . If the first diagonal entry of K a11 ww is positive, we can
factor it as A1 = R2T A2 R2 and hence A = R1T R2T A2 R2 R1 . By repeating this
process until An = I, we finally have
A = RT R,
where R = Rn · · · R2 R1 .
P
From aij = k rki rkj , we can derive rij as follows:
8 q Pi 1 2
< aii k=1 rki if i = j
rij = ⇣ ⌘
: 1 aij Pi 1 rki rkj if i < j .
rii k=1
for i = 1 : n do
r(i, i : n) = a(i, i : n) r(1 : i 1, i)T ⇤ r(1 : i 1, i : n)
p
r(i, i : n) = r(i, i : n)/ r(i, i)
end
Algorithm 4: Cholesky factorization
In the above algorithm, elements with zero indices are assumed to be zero.
A solution of Ax = b using the Cholesky factorization can be computed by
solving two triangular systems.
1. Solve RT y = b. (forward-substitution)
2. Solve Rx = y. (back-substitution)
2.2.4 QR factorization
Gram-Schmidt orthogonalization
v1
v1 = a1 q1 =
||v1 ||
v2
v2 = a2 ha2 , q1 iq1 q2 =
||v2 ||
.. ..
. .
n
X1 vn
vn = an hqi , an iqi qn =
i=1
||vn ||
for i = 1 : n do
vi = ai
for j = 1 : i 1 do
rji = hqj , ai i
vi = vi rji qj
end
rii = ||vi ||
vi
qi =
rii
end
Algorithm 5: Classical Gram-Schmidt orthogonalization
P1 a 1 P2 a 2 Pn a n
q1 = , q2 = , ··· , qn = .
||P1 a1 || ||P2 a2 || ||Pn an ||
2.2. DIRECT APPROACH 31
for i = 1 : n do
vi = ai
end
for i = 1 : n do
rii = ||vi ||
vi
qi =
rii
for j = i + 1 : n do
rij = hqi , vj i
vj = vj rij qi
end
end
Algorithm 6: Stable Gram-Schmidt orthogonalization
Householder factorization
vv T
H=I 2
vT v
for i = 1 : n do
x = A(i : m, i)
vi = x + sgn(x1 )||x||e1
vi
vi =
||vi ||
R(i : m, i : n) = A(i : m, i : n) 2vi viT A(i : m, i : n)
end
Algorithm 7: Householder factorization
for i = 1 : n do
b(i : m) = b(i : m) 2vi viT b(i : m)
end
Algorithm 8: Calculation of QT b
We will count operations of multiplication and division only because these op-
erations demand much more computational resources than the other operations
such as addition, subtraction, and substitution.
Pn 1
• LU factorization: k=1 (n k)(n k + 2) = 13 O(n3 )
Pn
• back-substitution: k=1 (n k + 1) = 12 O(n2 )
Pn
• Cholesky factorization: k=1 k(n k + 1) = 16 O(n3 )
Pn
• Gram-Schmidt orthogonalization: k=1 2m(k 1) + n + 2 = O(mn2 )
Pn
• Householder factorization: k=1 1 + (m k + 1)(3 + 2(n k + 1) =
2 1 3
O(mn 3n )
Pn
• Calculating QT b : k=1 (m k + 1)(m k) = O( 13 n3 + m2 n mn2 )
2.3.1 Motivation
1
(r2 u)ij = ui+1,j + ui 1,j + ui,j+1 + ui,j 1 4uij = fij ,
h2
Direct methods for solving linear systems theoretically give the exact solution in
a finite number of steps. Unfortunately, this is rarely true in many applications
because of rounding errors: an error made in one step spreads further in all
following steps. Contrary to direct methods, iterative methods construct a
series of solution approximations such that it converges to the exact solution of
a system. In this section, we seek iterative approaches to solve Ax = b.
⇢(A) = max | i |,
A=P N,
Proof. Let us define an error at the kth step e(k) = x(k) x⇤ , where x⇤ is the
solution of Ax = b. Then
e(k+1) = x(k+1) x⇤
= Bx(k) + P 1
b x⇤
= B(x(k) x⇤ + x⇤ ) + P 1
b x⇤
= Be(k) + (B I)x⇤ + P 1
b
= Be(k) + P 1
(N P )x⇤ + b
= Be(k) .
Hence e(k) converges to zero, in another word, x(k) converges to the solution x⇤
as k ! 1, i↵ ⇢(B) < 1.
x(k+1) = D 1
(D A)x(k) + D 1
b
1
=D b (A D)x(k)
or
1 ⇣ ⌘
n
X
(k+1) (k)
xi = bi aij xj .
aii j=1
j6=i
P = D + L, N= U.
2.3. ITERATIVE APPROACH 37
It results in
x(k+1) = (D + L) 1
b U x(k)
1 1 1
= (I + D L) D b U x(k) .
It is equivalent to
1
(I + D L)x(k+1) = D 1
b U x(k)
or
x(k+1) = D 1
b Lx(k+1) U x(k) .
Finally we have
1 ⇣ ⌘
i 1
X n
X
(k+1) (k+1) (k)
xi = bi aij xj aij xj , i = 1, 2, · · · , n.
aii j=1 j=i+1
Proposition 5.
⇢(BG ) = ⇢(BJ )2 .
Proof.
= x(k) + P 1
b Ax(k)
1
= (I P A)x(k) + P 1
b
1
= I P (P N ) x(k) + P 1
b
1
=P N x(k) + P 1
b.
38 CHAPTER 2. SOLVING LINEAR SYSTEM
1 (k)
You can consider P r as a relaxation term to correct the approxima-
tion. So it could be possible to introduce a relaxation factor w to control the
convergence rate. A generalized relaxation method has the form
x(k+1)
w = x(k) + wP 1 (k)
r .
(k+1) (k+1)
Proposition 6. xw = (1 w)x(k) + wx(k+1) , where xw and x(k+1) de-
note update of x at the (k + 1)th step with relaxation and without relaxation,
respectively.
Proof.
x(k+1)
w = x(k) + wP 1 (k)
r
= x(k) + wP 1
(b Ax(k) )
1
= (I wP A)x(k) + wP 1
b
= (1 w)x(k) + w(I P 1
A)x(k) + wP 1
b
= (1 w)x(k) + w P 1
N x(k) + P 1
b
= (1 w)x(k) + wx(k+1) .
w⇣ ⌘
i 1
X n
X
(k+1) (k) (k+1) (k)
xi = (1 w)xi + ai aij xj aij xj .
aii j=1 j=i+1
x(k+1) = (1 w)x(k) + wD 1
b Lx(k+1) U x(k) .
2.3. ITERATIVE APPROACH 39
Arranging it,
1
(I + wD L)x(k+1) = (1 w)I wD 1
U x(k) + wD 1
b.
1 1 1
Hence B = (I + wD L) (1 w)I wD U and we check its convergence
condition.
1 1
B = (I + wD (1 w)I wD 1 U
L)
⇣ ⌘
1
= D 1 (D + wL) D 1 (1 w)D wU
⇣ ⌘
= (D + wL) 1 D D 1 (1 w)D wU
1
= (D + wL) (1 w)D wU .
2
wopt = p .
1+ 1 ⇢(BJ )2
Note that in order to compute wopt , we should know the spectral radius of the
Jacobi iteration, which requires an impractical amount of computation. However
inexpensive rough estimates of wopt (for example, from the power method) can
improve the convergence rate.
Corollary 16.
!2
⇢(B )
⇢(Bopt ) = p J .
1 + 1 ⇢(BJ )2
40 CHAPTER 2. SOLVING LINEAR SYSTEM
Problem Set
1. Suppose we are given a set of vectors {x1 , · · · , xp }, xi 2 Rn , i = 1, · · · , p.
Find the vector x̄ 2 Rn such that the average squared distance between x̄
and x1 , · · · , xp ,
p
1X
||x̄ xi ||2 ,
p i=1
is minimized.
4. Given ↵ 2 R, find x̃ such that x̃ = arg minx ||Ax b||2P + ↵2 ||x x0 ||2Q ,
where ||x||P stands for the weighted norm, that is, ||x||P = xT P x.
5. Given a matrix 2 3
1 1 1 0
6 7
6 7
6 2 1 2 17
A=6
6
7,
7
6 2 0 1 37
4 5
2 1 1 3
6. For a matrix 2 3
25 5 10
6 7
6 7
A=6 5 17 107 ,
4 5
10 10 62
vv T
H=I 2 .
vT v
1
(a) Show that H = H T = H.
and
vT x
x 2 v,
vT v
where x 2 Rn .
(b) Assume that i, the ith eigenvalue of A are all real and such that,
min i max . Show that µi , the ith eigenvalues of B satisfies
1 ↵ max µi 1 ↵ min .
(c) Show that if min < 0 and max > 0, then ⇢(B) > 1 for any ↵, which
means that the method will always diverge.
(d) Assume that all eigenvalues of A are positive, i.e., min > 0. Show
that the following conditions must be satisfied for the method to
converge:
1 ↵ min <1
1 ↵ max > 1,
or equivalently
2
0<↵ .
max
(g) Show that the optimal value ↵opt for the parameter ↵, i.e., the value
of ↵ which minimizes ⇢(B) is
2
↵opt = .
max + min
max min
⇢opt (G) = .
max + min
[ Note: It depicts the difficulty with the presence of small and large
eigenvalues. The convergence rate can be extremely small for realistic
problems. In addition, to achieve good convergence, eigenvalue esti-
mates are require to obtain the optimal or near-optimal ↵, and this
may be difficult. These observations are common to many iterative
methods that depends on an acceleration parameter. ]
x(k+1) = b Ax(k) .
Representing Rotation
so(n) = {S 2 Rn⇥n |S T + S = 0}
45
46 CHAPTER 3. REPRESENTING ROTATION
R[ w ]RT = [ Rw ].
Proof. Without
loss of generality, we prove that RT [ w ]R = [ RT w ]. Assume
p p p
that R = r1 r2 r3 .
p p p
" # " #
r1T p p p r1T p p p
T
R [ w ]R = r2T [w] r 1 r 2 r3 = r2T w⇥r1 w⇥r2 w⇥r3
p p p p p p
r3T r3T
2 3
hr1 , w ⇥ r1 i hr1 , w ⇥ r2 i hr1 , w ⇥ r3 i
6 7
6 7
= 6hr2 , w ⇥ r1 i hr2 , w ⇥ r2 i hr2 , w ⇥ r3 i7
4 5
hr3 , w ⇥ r1 i hr3 , w ⇥ r2 i hr3 , w ⇥ r3 i
2 3
hw, r1 ⇥ r1 i hw, r2 ⇥ r1 i hw, r3 ⇥ r1 i
6 7
6 7
= 6hw, r1 ⇥ r2 i hw, r2 ⇥ r2 i hw, r3 ⇥ r2 i7
4 5
hw, r1 ⇥ r3 i hw, r2 ⇥ r3 i hw, r3 ⇥ r3 i
2 3
0 hw, r3 i hw, r2 i
6 7
6 7 T
= 6 hw, r3 i 0 hw, r1 i7 = [ R w ].
4 5
hw, r2 i hw, r1 i 0
Proof.
T
kRq Rpk2 = R(q p) R(q p) = (q p)T RT R(q p) = kq pk2 .
2
[ w ] = wwT kwk2 I
3
[w] = kwk2 [ w ]
2
exp(✓[ w ]) = I + sin ✓[ w ] + (1 cos ✓)[ w ] ,
where ✓ 2 R, kwk = 1.
Proof.
1 2 2 1 3 1 4
exp(✓[ w ]) = I + ✓[ w ] + ✓ [ w ] + ✓3 [ w ] + ✓4 [ w ] + · · ·
2! 3! 4!
1 3 1 1 4 2
= I + (✓ ✓ + · · · )[ w ] + ( ✓2 ✓ + · · · )[ w ]
3! 2! 4!
2
= I + sin ✓[ w ] + (1 cos ✓)[ w ]
48 CHAPTER 3. REPRESENTING ROTATION
exp([ w ]) 2 SO(3).
1
Proof. Let R = exp([ w ]). It is sufficient to show that R = RT and det R = 1.
1 T
exp([ w ]) = exp( [ w ]) = exp([ w ] ) = exp([ w ])T .
It is obvious that det exp([ 0 ]) = det I = 1. Using the continuity of the deter-
minant as a function of the entries of a matrix, we conclude that det R = 1.
Since we have the exponential mapping which maps so(3) to SO(3), we can
use a skew-symmetric matrix to parameterize a rotation matrix, if we have the
inverse of the mapping.
2
exp(✓[ w ]) = I + sin ✓[ w ] + (1 cos ✓)[ w ]
2 3
wx2 v✓ + c✓ w x w y v✓ wz s✓ wx wz v✓ + wy s✓
6 7
6 7
= 6wx wy v✓ + w z s✓ wy2 v✓ + c✓ wy wz v✓ wx s✓ 7 .
4 5
wx w z v✓ wy s✓ w y w z v✓ + w x s✓ wz2 v✓ + c✓
If ✓ 6= 0, we choose 2 3
r32 r23
1 6 7
6 7
w= 6r13 r31 7 .
2 sin ✓ 4 5
r21 r12
Note that if 2⇡ ✓ had been chosen earlier, the axis of rotation would have
been w. Indeed, the exponential map is a surjective(many-to-one) map from
R3 onto SO(3). If R 6= I, the above construction shows that there are two
distinct w and ✓ 2 [ 0, 2⇡) such that R = exp([ w ]).
Figure 3.1 illustrates rotating a vector p by an angle ✓ about an axis w,
where kwk = 1. Then the rotated vector q is
= exp(✓[ w ])p .
Now we can figure out the geometric meaning of exp(✓[ w ]). That is why the
parameterization using the exponential map has aliases of an angle-axis repre-
sentation or an equivalent axis representation.
then rotate about the (one again, new) x-axis of frame {B} by an angle . This
yields a net orientation R(↵, , ) and the the triple of angles (↵, , ) is called
the ZYX Euler angles.
The rotation matrix R(↵, , ) is given as
↵ = atan2(r21 , r11 )
q
= atan2( r31 , 2 + r2 )
r11 21
= atan2(r32 , r33 ) .
h 0 cos ↵ sin sin ↵ cos cos ↵ cos +sin ↵ sin i
Note that when = ⇡/2, R = 0 sin ↵ sin +cos ↵ cos sin ↵ cos cos ↵ sin =
1 0 0
h 0 sin(↵ ) cos(↵ ) i
0 cos(↵ ) sin(↵ ) , which means that there exist infinitely many choices
1 0 0
of ↵ and for the given R. Similar things happen when = ⇡/2. This
singularity problem is often called a gimbal lock. Any kinds of Euler angles
3.5. QUATERNIONS 51
has the singularity problems. So we have to be careful about it. It has been
proven mathematically that there exists no single parameterization of the rota-
tion group which is free from singularity.
3.5 Quaternions
q = s + v1 i + v2 j + v3 k, s, vi 2 R, i = 1, · · · , 3,
ai = ia aj = ja ak = ka a2R
i·i=j·j=k·k=i·j·k= 1
Proposition 11. Given two quaternions q = (s, v) and p = (t, w), the product
between two quaternions has a simple form in terms of the inner and cross
products between vectors in R3 as follows:
kqk2 = q · q ⇤ = s2 + kvk2 .
52 CHAPTER 3. REPRESENTING ROTATION
Proof.
kqpk2 = (qp)(qp)⇤ = (qp)(p⇤ q ⇤ ) = qkpk2 q ⇤ = kqk2 kpk2 .
Lemma 11.
1 = (1, 0)
1 q⇤
q = .
kqk2
Proof. Below we write S(q) = 12 (q +q ⇤ ) for the real part of q. The proof consists
of three steps. We first show S(p0 ) = S(p) for p 2 {(s, 0)|s 2 R} and then for
p 2 {(0, v)|v 2 R3 }. Finally these results are combined to prove the proposition
for p 2 H.
3.5. QUATERNIONS 53
1. Let p = (s, 0). Then p0 = q(s, 0)q ⇤ = sqq ⇤ = s. Hence S(p0 ) = S(p) = s.
= 0, exp(2✓[ w ])r .
Q = cos(✓/2), sin(✓/2) w ,
Thus, the group operation on unit quaternions directly corresponds to the group
operation for rotations. Given a unit quaternion q = (s, v), we can extract the
54 CHAPTER 3. REPRESENTING ROTATION
Note that the exponential and logarithmic functions are mutually inverse,
and the exponential function maps into H1 .
From the above definitions, we can define exponentiation for q 2 H1 , t 2 R:
q t = exp t log(q) .
q a q b = q a+b .
3.5. QUATERNIONS 55
Proof.
= exp (a + b) log(q)
= q a+b .
Proof.
= exp t log(qpq ⇤ )
= (qpq ⇤ )t .
Proof. Let q = (cos ✓, sin ✓w). Then kq t k = k exp t log(q) k = k exp t(0, ✓w) k =
k exp (0, t✓w) k = k(cos(t✓), sin(t✓)w)k = 1.
Proof.
= q(p⇤ q) t
= pp⇤ q(p⇤ q) t
= p(p⇤ q)1 t
= Slerp(p, q, 1 t).
Problem Set
n Rn + Rn T o
1. Show that a sequence Rn+1 = converges to a rotation ma-
2
trix, where R0 2 R3⇥3 is an arbitrary matrix. Implement the algorithm
and check the result numerically. You can use any computer languages(C,
C++, JAVA, matlab, ...)
2. Show that R = (I [ a ]) 1
(I + [ a ]) 2 SO(3), where a 2 R3 .
2
q = I + sin ✓[ w ] + (1 cos ✓)[ w ] p.
Introduction to
Optimization
59
60 CHAPTER 4. INTRODUCTION TO OPTIMIZATION
minimize f (x)
subject to x 2 ⌦.
@f f (x + ↵d) f (x)
= lim .
@d ↵!1 ↵
Lemma 16.
@f
= dT rf (x)
@d
Proof.
@f d
= f (x + ↵d)
@d d↵ ↵=0
T
= rf (x) d
= dT rf (x)
f (x⇤ + d) f (x⇤ )
0 .
By taking limits as ! 0,
0 dT rf (x⇤ ), 8d 2 Rn .
dT H(x⇤ )d 0,
where g (k) 2 Rn is called the step direction or search direction, ↵k is called the
step size. Given a starting point x 2 Rn , general descent methods repeat the
following procedures until stopping criterion is satisfied.
Then our questions will be how to choose the search direction and the step size.
g= rf (x).
The resulting algorithm is called the gradient algorithm. The gradient method
often exhibits linear convergence and the convergence rate depends greatly on
the condition number of the Hessian. Consequently, it is very simple, but rarely
used in practice due to its slow convergence.
4.2. UNCONSTRAINED OPTIMIZATION 63
T
d(i) Qd(j) = 0.
T
Premultiplying the above equality by d(j) Q, 1 j k, yields
T
↵j d(j) Qd(j) = 0
T
because all other terms d(j) Qd(i) = 0, i 6= j, by Q-conjugacy. Here Q is positive
definite, so ↵j = 0, j = 1, · · · , k. Therefore d(1) , d(2) , · · · , d(k) , k n are linearly
independent.
Now we present the conjugate direction algorithm for minimizing the quadratic
function of n variables
1 T
f (x) = x Qx xT b,
2
where Q is positive definite, x 2 Rn . Note that since Q > 0, the function f has
a global minimizer that can be found by solving Qx = b.
[Basic Conjugate Direction Algorithm] Given a starting point x(1) , and
Q-conjugate directions d(1) , d(2) , · · · , d(n) ; for k 0,
Theorem 18. For any starting point x(1) , the basic conjugate direction al-
gorithm converges to the unique x⇤ which solves Qx = b in n steps; that is,
x(n+1) = x⇤ .
Proof. Consider x⇤ x(0) 2 Rn . Because the d(i) are linearly independent, there
exist constant i, i = 0, · · · , n, such that
x⇤ x(1) = 1d
(1)
+ ··· nd
(n)
.
T
Now pre-multiply both sides of the above equation by d(k) Q, 1 k n, to
obtain
T (k) T
d(k) Q(x⇤ x(1) ) = kd Qd(k) ,
T
where the terms d(k) Qd(i) = 0, k 6= i, by the Q-conjugate property. Hence
T
d(k) Q(x⇤ x(1) )
k = T
.
d(k) Qd(k)
Therefore,
x(k) x(1) = ↵1 d(1) + · · · + ↵k d(k) .
So writing
x⇤ x(1) = x⇤ x(k) + x(k) x(1)
T
and pre-multipying the above by d(k) Q, we obtain
T T T
d(k) Q(x⇤ x(1) ) = d(k) Q(x⇤ x(k) ) = d(k) g (k)
T
g (k+1) d(i) = 0
T
then by Q-conjugacy, d(k) Qd(i) = 0, and hence
T T T
g (k+1) d(i) = g (k) d(i) + ↵k d(k) Qd(k) = 0.
T
g (k+1) d(k) = 0.
4.2. UNCONSTRAINED OPTIMIZATION 67
Indeed,
T
g (k+1) d(k) = (Qx(k+1) b)T d(k)
✓ T ◆ !T
(k) g (k) d(k) (k)
= x T
d Qd(k) bT d(k)
d(k) Qd(k)
T
= (x(k) Q b)T d(k) g (k) d(k)
=0
d(k+1) = g (k+1) kd
(k)
, k = 1, 2, · · · .
7. d(k+1) = g (k+1) kd
(k)
.
8. Set k := k + 1; goto 3.
Proposition 16. In the conjugate gradient algorithm, the direction d(1) , · · · , d(n)
are Q-conjugate.
T
Proof. We use induction. We first show d(1) Qd(2) = 0.
T T
d(1) Qd(2) = d(1) Q g (2) + 1 d(1)
✓ T ◆
T g (2) Qd(1) (1)
= d(1) Q g (2) T
d
d(1) Qd(1)
T
(1) T (2) g (2) Qd(1) T
=d Qg T
d(1) Qd(1)
d(1) Qd(1)
= 0.
Now assume that d(1) , · · · , d(k) , k < n are Q-conjugate directions. From Lemmm 18,
T
we have g (k+1) d(i) = 0, j = 1, · · · , k. Thus g (k+1) is orthogonal to each of the
directions d(1) , · · · , d(k) . We now show that
T
g (k+1) g (j) = 0, j = 1, · · · , k.
T
It remains to be shown that d(k+1) Qd(k) = 0. We have
T
d(k+1) Qd(k) = ( g (k+1) + kd
(k) T
) Qd(k) .
T
Using the expression for k, we get d(k+1) Qd(k) = 0, which completes the
proof.