CS 418: Homework Solutions - Vector and Matrix Operations, Assignments of Computer Graphics

Solutions to various vector and matrix operations as part of a university-level computer science course. Topics include vector length, angle between vectors, unit vectors perpendicular to given vectors, determinants, matrix inverses, and matrix-vector multiplication.

Typology: Assignments

Pre 2010

Uploaded on 03/16/2009

koofers-user-b0o
koofers-user-b0o 🇺🇸

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 418: Homework #1
Solution
1. (15pt)
(a) Let v= [ 5 3 7 ]. Compute kvk, the vector length of v.
Solution:
kvk=p52+ 32+ 72=83 9.11
(b) Let u= [ 2 3 1 ] and v= [ 5 3 7 ]. Compute the angle umakes with v. Express your answer in radians.
Solution:
cos θ=u·v
kuk∗kvk=26
1162
θ= cos126
1162=cos1(0.7627) = 0.703 radian
(c) Let u= [ 2 3 1 ] and v= [ 5 3 7 ]. Find a unit vector perpendicular to both uand v.
Solution:
u×v=
i j k
2 3 1
5 3 7
=
3 1
3 7
i
2 1
5 7
j+
2 3
5 3
k= [ 18 99 ]
Unitize u×v, the result is h2
61
61
6i
(d) Given a vector v= [x y], show that the vector u= [y x]is orthogonal (i.e., perpendicular) to v.
Solution:
Two vectors u,vare perpendicular iff u·v= 0, and [x y]·[y x] = x(y) + yx = 0
2. (15pt) Suppose you are given matrices
M=
121
034
04 3
,
N=
100
110
111
and vectors u=
2
3
1
,v=
x
y
z
.
pf3
pf4
pf5

Partial preview of the text

Download CS 418: Homework Solutions - Vector and Matrix Operations and more Assignments Computer Graphics in PDF only on Docsity!

CS 418: Homework

Solution

  1. (15pt)

(a) Let v = [ 5 3 7 ]. Compute ‖v‖, the vector length of v.

Solution:

‖v‖ =

52 + 3^2 + 7^2 =

(b) Let u = [ 2 3 1 ] and v = [ 5 3 7 ]. Compute the angle u makes with v. Express your answer in radians.

Solution:

cos θ =

u·v ‖u‖ ∗ ‖v‖

θ = cos−^1

= cos−^1 (0.7627) = 0. 703 radian

(c) Let u = [ 2 3 1 ] and v = [ 5 3 7 ]. Find a unit vector perpendicular to both u and v.

Solution:

u×v =

i j k 2 3 1 5 3 7

∣ i^ −

∣ j^ +

∣ k^ = [ 18^ −^9 −^ 9 ]

Unitize u×v, the result is

[

√^2 6 −^ √^1 6 −^ √^1 6

]

(d) Given a vector v = [x y], show that the vector u = [−y x] is orthogonal (i.e., perpendicular) to v.

Solution:

Two vectors u, v are perpendicular iff u·v = 0, and [x y]·[−y x] = x(−y) + yx = 0

  1. (15pt) Suppose you are given matrices

M =

N =

and vectors u =

, v =

x y z

(a) Compute the determinant det M.

Solution:

det M = 1 ·

∣ −^0 ·

∣ + 0^ ·

(b) Compute the inverse M−^1.

Solution: We use elementary row operations to find the inverse of M.  

So M−^1 =

(c) Compute matrix-matrix multiplication MN.

Solution:

MN =

(d) Compute matrix-vector multiplication Mv.

Solution:

Mv =

x y z

x + 2y + z 3 y + 4z − 4 y + 3z

(e) Compute the multiplication uvT^.

Solution:

and vectors v =

x x^2 x^3

,^ G^ =

g 1 g 2 g 3 g 4

, where^ g 1 =

,^ g 2 =

,^ g 3 =

,^ g 4 =

. Compute

vT^ MG.

Solution:

vT^ M = [ 1 x x^2 x^3 ]

 = [ 1^ −^3 x^2 + 2x^3 3 x^2 −^2 x^3 x^ −^2 x^2 +^ x^3 −x^2 +^ x^3 ]

So vT^ MG = [ 1 − 3 x^2 + 2x^3 6 x^2 − 4 x^3 3 x − 6 x^2 + 3x^3 − 4 x^2 + 4x^3 ]

  1. (10pt) Suppose you are given the 2-D points p 1 = [x 0 y 0 ] and p 2 = [x 1 y 1 ]. Show that the equation of the line between them is (y 1 − y 0 )x − (x 1 − x 0 )y = y 1 x 0 − x 1 y 0.

Solution:

Suppose the line equation is ax + by + c = 0, and we know that

[

a b

]

is perpendicular to the line. Since vector

p 1 − p 2 =

[

x 0 − x 1 y 0 − y 1

]

is along the line, we know from question 1(d) that

[

y 1 − y 0 x 0 − x 1

]

is a vector perpendicular

to the line. We can use it as

[

a b

]

, which means a = y 1 − y 0 and b = x 0 − x 1.

Next we plug in p 0 to the line equation to get c. From ax 0 +by 0 +c = 0 we have (y 1 −y 0 )x 0 +(x 0 −x 1 )y 0 +c = 0, so c = x 1 y 0 − x 0 y 1. This gives us the equation in the problem statement.

  1. (15pt) The equation of a plane in 3-D space is ax + by + cz + d = 0. Given three points p 1 , p 2 , p 3 find the coefficients a, b, c for the plane containing the three given points.

Solution:

We follow a similar approach to the previous question. First, we compute a normal vector for the plane. Recall that given two vectors in the plane, their cross product will be perpendicular to the plane. Thus a normal vector is:

n =

a b c

 (^) = (p 2 − p 1 )×(p 3 − p 1 )

Given this normal and a point in the plane, we can solve for d:

n·p 1 + d = 0 d = −n·p 1

  1. (15pt) Let the matrix M(θ) be defined as follows:

M(θ) =

[

cos θ − sin θ sin θ cos θ

]

(a) A square matrix M is said to be orthogonal if and only if its inverse exists and M−^1 = MT. Show that M(θ) is orthogonal.

Solution: To show that M−^1 = MT, we simply need to show that MMT^ = I: [ cos θ − sin θ sin θ cos θ

] [

cos θ sin θ − sin θ cos θ

]

[

cos^2 θ + sin^2 θ cos θ sin θ − sin θ cos θ sin θ cos θ − cos θ sin θ sin^2 θ + cos^2 θ

]

[

]

(b) Show that M(θ 1 )M(θ 2 ) = M(θ 1 + θ 2 ).

Solution:

M(θ 1 )M(θ 2 ) =

[

cos θ 1 − sin θ 1 sin θ 1 cos θ 1

] [

cos θ 2 − sin θ 2 sin θ 2 cos θ 2

]

[

cos θ 1 cos θ 2 − sin θ 1 sin θ 2 −(sin θ 1 cos θ 2 + cos θ 1 sin θ 2 ) sin θ 1 cos θ 2 + cos θ 1 sin θ 2 cos θ 1 cos θ 2 − sin θ 1 sin θ 2

]

[

cos(θ 1 + θ 2 ) − sin(θ 1 + θ 2 ) sin(θ 1 + θ 2 ) cos(θ 1 + θ 2 )

]

= M(θ 1 + θ 2 )

(c) Show that, for all possible values of θ, the inverse of M(θ) is M(−θ).

Solution: Using the result from part (b), we know that

M(θ)M(−θ) = M(θ + (−θ)) = M(0) =

[

cos 0 − sin 0 sin 0 cos 0

]

[

]

So we proved that M(θ) and M(−θ) are inverses of each other.