Applied Linear Algebra: Inner Product and Cosines
Applied Linear Algebra: Inner Product and Cosines
Applied Linear Algebra: Inner Product and Cosines
The cosine of the angle θ = β − α using inner products. For angle β, the sine is
b2 b1
and the cosine is .
kbk kbk
cos θ = cos(β − α)
= cos β cos α + sin β sin α
a1 b 1 + a2 b 2
=
k a kk b k
aT b
=
k a kk b k
ha, bi
=
k a kk b k
Example 1 Project b = (1, 2, 3) onto the line through a = (1, 1, 1) to get xb and p.
T
a b 1+1×2+1×3 6
Solution: x b = T = √ = = 2. The projection is p = xba =
a a 2 2
( 1 +1 +1 ) 2 2 3
aT b 6
2(1, 1, 1) = (2, 2, 2). The angle between a and b is cos θ = =√ √ .
k a kk b k 3 14
Schwartz Inequality | ab |≤k a kk b k .
2
Exercise-3.2
1. (a) Given any two positive numbers x and y, choose the vector b equal to
√ √
√ √
( x , y), and choose a = y , x ). Apply the Schwarz inequality
1 √
to compare the arithmetic mean (x + y) with the geometric mean xy.
2
√
√
y x
solution: If a = √ , b = √ . Applying Schwarz inequality, we
x y
get
aT b ≤k a kk b k
√
√ √ x
√ √ √ √
⇒ y x √ ≤k ( y, x) kk ( x, y) k
y
√ √
q
√ 2 √ 2q √ 2 √
⇒ xy + xy ≤ ( y) + ( x) ( x) + ( y)2
√ √ √
⇒ 2 xy ≤ y + x x + y
√ x+y
⇒ xy ≤ (G.M. ≤ A.M.)
2
k x + y k≤k x k + k y k
⇒k x + y k2 ≤ (k x k + k y k)2
⇒ (x + y)T (x + y) ≤k x k2 +2 k x kk y k + k y k2
⇒ (xT + y T )(x + y) ≤k x k2 +2 k x kk y k + k y k2
⇒ xT x + xT y + y T x + y T y ≤k x k2 +2 k x kk y k + k y k2
⇒k x k2 +2xT y+ k y k2 ≤k x k2 +2 k x kk y k + k y k2
⇒ xT y ≤k x kk y k (Schwarz inequality).
3
ity, we have
aT b ≤k a kk b k
1
1 q √
⇒ a1 a2 · · · an . ≤ a21 + a22 + · · · + a2n 12 + 12 + · · · + 12
..
1
√ q 2
⇒ a1 + a2 + · · · an ≤ n a1 + a22 + · · · + a2n
Assignments
Exercise-3.2, Q. 5,9.
4
Lect-22
Remark 1
aaT
1. Projection matrix is same if a is doubled a = (2, 2, 2, ),.i.e,
aT a
1 1 1
3 3 3
2
aaT 1
1 1 1
P = T = 2 2 2 2 = .
a a 12
3 3 3
2
1 1 1
3 3 3
aaT
2. To project b onto a, multiply it by the projection matrix P : p = P b, P = T
a a
5
Exercise-3.2
aaT
8. Prove that the trace of P = , which is the sum of its diagonal entries, always
aT a
1.
Solution: Let a = (a1 a2 · · · an )T . Then
aaT
P =
aT a
a1
a
2
. a1 a2 · · · an
..
an
=
a1
a2
a1 a2 · · · an .
..
an
a21 a1 a2 · · · a1 an
2
a a
1 2 a 2 · · · a 2 a n
. .. .. ..
.. . . .
2
an a1 an a2 · · · an
=
a21 + a22 + · · · + a2n
cos θ 1
(a) b = and a =
sin θ 0
6
Solution:
P =x
ba
aT b
= a
aT a
cos θ
1 0
sin θ 1
=
1 0
1 0
0
cos θ 1
=
1 0
cos θ
=
0
1 1
(b) b = and a =
1 −1
7
Solution:
P =x
ba
aT b
= a
aT a
1
1 −1
1 1
=
1 −1
1 −1
−1
0 1
=
2 −1
0
=
0
Assignments
Exercise-3.2, Q. 11,19.
8
Lect-23
Ax = b (2)
with b 6∈ C(A). Then (2) has no solution. Then one must choose x
b a best fit solution
of it.
9
As b 6∈ C(A), let us obtain a column vector p in C(A), which is the most closest vector
of b in C(A) such that the error e = b − p is of minimum length .i.e,k e k2 =k b − p k2
is minimum. Hence it is called least square approximation.
k e k2 is minimum
⇐⇒ e ⊥ C(A)
⇐⇒ e ∈ N (AT )
⇐⇒ AT e = 0
⇐⇒ AT (b − p) = 0
⇐⇒ AT (b − Ab
x) = 0
⇐⇒ AT b = AT Ab
x
p = A(AT A)−1 AT Ax = Ax = b :
3. When A is square and invertible, the column space is the whole space. Every
vector projects to itself, p equals b, and x
b = x : If A is invertible
This is the only case when we can take apart (AT A)−1 , and write it as A−1 (AT )−1 .
When A is rectangular that is not possible.
4. Suppose A has only one column, containing a. Then the matrix AT A is the
number aT a and x
b is aT b = aT a.
10
5. AT A has the same nullspace as A.
xT AT Ax = 0 ⇒k Ax k2 = 0 ⇒ Ax = 0.
Projection Matrices
i.e, p = P b.
Note that
and
P T = [A(AT A)−1 AT ]T
= (AT )T [(AT A)−1 ]T AT
= A(AT A)−1 AT
= P.
P = A(AT A)−1 AT
= AA−1 (AT )−1 AT
= I.
11
1 0 1
1. Solve Ax = b by least squares and find p = Ab x, if A =
0 1 and 1. Verify
1 1 0
that the error b − p is perpendicular to the columns of A.
Solution:
b = (AT A)−1 AT b
x
1
1 2 −1 1 0 1
= 1
3 −1 2 0 1 1
0
1
3
=
1
3
and
P = Ab
x
= (AT A)−1 AT b
1 0 1
3
=0 1 1
1 1 3
1
3
1
= .
3
2
3
1 2
3 3
1
1 2
Here, Error= b − p = 1 −
3 = .
3
0
2 −2
3 3
b − p is perpendicular to thecolumn
of the matrix.
1
2 2 −2 2 2
(b − p)T C1 = 0 = − = 0 and
3 3 3 3 3
1
12
0
2 2 −2 2 2
(b − p)T C2 = 1 = − = 0.
3 3
3 3 3
1
1 −1 4
C
4. The following system has no solution: Ax = 1 0
= 5 = b.
D
1 1 9
Sketch and solve a straight-line fit that leads to the minimization of the quadratic
(C − D − 4)2 + (C − 5)2 + (C + D − 9)2 . What is the projection of b onto the
column space of A?
Solution:
b = (AT A)−1 AT b
x
1 4
0 1 1 1
= 3 1 5
−1 0 1
0
2 9
1 1 1
3 3 3 4
= 5
−1 1
0 9
2 2
6
= 5 .
2
Now,
P = Ab
x
1 −1
6
= 1 0 5
1 1 2
7
2
= 6 .
17
2
Assignments
Exercise-3.3, Q. 2,9,12,24.
13
Lect-24
b = C + Dt
or
C + Dt1 = b1
C + Dt2 = b2
..
.
C + Dtm = bm
1 t1 b1
1 t C b
2 2
or . = . or Ax = b, x b = (C,
b D).
b
.. ..
D
1 tm bm
m
X
E 2 =k b − Ax k2 = (bi − C − Dti )2 , where k E k2 is minimum for some C and D.
i=1
∂E 2
=0 (3)
∂C
∂E 2
=0 (4)
∂D
Solving (3) and (4) for C and D we get the required straight line
b = C + Dt.
14
or
1 t1
1 t
2
AT Ab
x = AT b, A = .
..
1 tm
C
b
⇐⇒ AT A = AT b
Db
1 t1 b1
1 1 ... 1 1 t2 C 1 1 ... 1 b2
b
⇐⇒ . = .
. .
t1 t2 . . . tm .
D
b t1 t2 . . . tm .
1 tm bm
Xm Xm
m t bi
i C
i=1 b i=1
⇐⇒ X = X
m m m
ti
X
2
ti D
b
ti bi
i=1 i=1 i=1
15
Exercise-3.3
1 1 1
A=
1 ,
−1 b=
2 .
−2 4 7
Split b into p + q, with p in the column space and q perpendicular to that space.
Which of the four subspaces contains q?
Solution:
p = Ab
x
18 8
1 1 44 44 1
1 1 −2
=
1 −1 8
6
2
1 −1 4
−2 4 44 44 7
26 14
44 44
1
10
2 1
1 −2
= 2
44 44 −1 4
1
7
−4 8
44 44
40 12 4
44 44 44
1
12 8 −12
= 2
44 44 44
7
4 −12 40
44 44 44
92
1
= −56 .
44
260
92 1
1
Let find the vector q such that b = p + q ⇒ q = p − b = −56 − 2 =
44
260 7
16
48 48 1 1 0
1
−144 . Thus, q A = T 1
−144 1 −1 = 0. Hence, q belongs
44 44
−48 −48 −2 4 0
to the left null space.
Assignments
Exercise-3.3, Q. 12,24.
17
Lect-25
a b c a b c
e f d f d e
2. det − b
d e f = d e f = a
+ c
h i g i g h
g h i g h i
1 0 0
1 0
3. The determinant of the identity matrix is 1, eg-
= 1 and 0 1 0 = 1
0 1
0 0 1
a b b a
4. The determinant changes sign when two rows are interchanged,i.e., = −
.
c d d c
0 0
a + a b + b a b
5. The determinant depends linearly on the first row, i.e., = +
c d c d
0 0
a b ta tb a b
and = t .
c d c d c d
a a
6. If any two rows of A are equal then det(A) = 0, eg,
= 0.
c c
7. Substracting a multiple of one row from another row leaves the same determinant.
9. det(AB) = det(A)det(B)
18
Exercise-4.2
1 2 −2 0
2 3 −4 1
(i) det .
−1 −2 0 2
0 2 5 3
Solution:
1 2 −2 0 1 2 −2 0
2 3 −4 1 0 −1 0 1
= R2 → R2 − 2R1 , R3 → R3 + R1
−1 −2 0 2 0 0 −2 1
0 2 5 3 0 2 5 3
1 2 −2 0
0 −1 0 1
= R4 → R4 + 2R2
0 0 −2 2
0 0 5 5
1 2 −2 0
0 −1 0 1 5
= R4 → R4 + R3
2
0 0 −2 2
0 0 0 10
2 −1 0 0
−1 2 −1 0
(ii) det .
0 −1 2 −1
0 0 −1 −2
19
Solution:
0 2 −1 0 0
2 −1 0
3
−1 2 −1 0 0 −1 0
1
=
2 R2 → R2 + R1
2
0 −1 2 −1 0 −1 2 −1
0 0 −1 −2 0 0 −1 −2
2
−1 0 0
3
0 −1 0
2 R3 → R3 + 2
= 4 R2
0 0
−1 3
3
0 0 −1 −2
2 −1 0 0
3
−1 0
0 3
=
2 R4 → R4 +
R3
4 4
0 0 −1
3
0 5
0 0
4
3 4 5
= 2 × × × = 5.
2 3 4
Solution:
20
1 2 −1 2 2 −1 2
(a) A = 4
2 −1 2 = 8 −4 8 . Hence, det(A) = 8 −4 8 =
2 4 −2 4 4 −2 4
2
−1 2
0
0 0 = 0
0 0 0
(b) | U |= 4 × 1 × 2 × 2 = 16
Assignments
Exercise-4.2, Q. 2,6,13.
21