0% found this document useful (0 votes)
105 views

Lab 6 Applied Linear Algebra For It - 501032: 1 Exercises

The document provides a series of exercises involving linear algebra concepts such as norms, vectors, matrices, and cosine similarity. Specifically, it contains 10 exercises asking students to write code to calculate 1-norms, infinity-norms, Euclidean norms, angles between vectors, unit vectors, distances between points, matrix encoding/decoding, and document similarity based on cosine similarity measures.

Uploaded by

Anh Quoc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views

Lab 6 Applied Linear Algebra For It - 501032: 1 Exercises

The document provides a series of exercises involving linear algebra concepts such as norms, vectors, matrices, and cosine similarity. Specifically, it contains 10 exercises asking students to write code to calculate 1-norms, infinity-norms, Euclidean norms, angles between vectors, unit vectors, distances between points, matrix encoding/decoding, and document similarity based on cosine similarity measures.

Uploaded by

Anh Quoc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Ton Duc Thang University

Faculty of Information Technology

Lab 6
APPLIED LINEAR ALGEBRA FOR IT - 501032

1 Exercises
Exercise 1: Write command to find 1-norm of the following matrices:

(a)   (c)   (e)


1 −7 2 −8
A1 = A3 = 
5 −4 2

−2 −3 3 1
A5 =  −1 2 3 
(b) (d)
    −2 1 0
−2 8 2 3
A2 = A4 =
3 1 1 −1

Note: Do not use the built-in function (i.e. norm function) to find norm.

Exercise 2: Write command to find infinity-norm of the following matrices:

(a) (c) (e)


 

1 −7
 5 −4 2 
−3 0 0

B1 = B3 =  −1 2 3 
−2 −3 B5 =  0 4 0 
−2 1 0 0 0 2
(d)
(b)  
  3 6 −1
3 6 B4 =  3 1 0 
B2 =
1 0 2 4 −7

Note: Do not use the built-in function (i.e. norm function) to find norm.

Exercise 3: Write command to find calculate the Euclidean-norm

(a) (b) (c)  


2 3

5 −4 2
 
1 7 3
 C3 =
1 −1
C1 =  −1 2 3  C2 =  4 −2 −2 
−2 1 0 −2 −1 1

Note: Do not use the built-in function (i.e. norm function) to find norm.

Anh H. Vo - [email protected] 1
Ton Duc Thang University
Faculty of Information Technology

Exercise 4: Let u and v be vectors in R2 . For the following u and v determine the angle between the
vectors.

(a)     (c)    
1 0 −2 1/2
u= , v= u= , v=
1 1 3 −1/2
(b)    
1 0
u= , v=
0 1

Exercise 5: Determine the unit vector û for each of the following vectors.

(a) u = (2, 3)T (c) u = (1/2, −1/2, 1/4)T


√ √ √ T
(b) u = (1, 2, 3)T (d) u = ( 2, 2, − 2 2)

Exercise 6: Let v1 = (1, 2, 3)T , s2 = (7, 4, 3)T , and s3 = (2, 1, 9)T be the position of three satellites.
Find the Euclidean distances between satellites.

 Write a function to decode


Exercise 7: the encoded
 following
 message 
80 98 99 85 106 94 1 2 3
E =  71 92 76 95 100 92 . Given A =  2 1 2  and lookup table
124 163 140 160 176 161 3 2 4

Hint: In order to decode the message D, you need to know the inverse matrix A−1 and then you
calculate A−1 E to get the matrix D. Remember that the matrix D contains the message. Finally,
using the above lookup table to obtain the message which can read.

Exercise 8: Using lookup table in the Exercise 8, write a function to encode the following message
• ATTACK
• LINEAR ALGEBRA LABORATORY
 
3 4 5
using the matrix A =  1 3 1 
1 1 2

Hint: In order to encode the message, you need to create the matrix E with lookup table and then
calculate AE.

Exercise 9: Write a function to calculate the similarities among documents. Consider the following document-
term matrix

Anh H. Vo - [email protected] 2
Ton Duc Thang University
Faculty of Information Technology

T1 T2 T3 T4 T5 T6 T7 T8
Doc1 0 4 0 0 0 2 1 3
Doc2 3 1 4 3 1 2 0 1
Doc3 3 0 0 0 3 0 3 0
Doc4 0 1 0 3 0 0 2 0
Doc5 2 2 2 3 1 4 0 2

kDoci ·Docj k1
Using the Cosine Similarity = kDoci k2 kDocj k2 . Cosine Similarity is used to measure the angle between
two unit length.
Exercise 10: Write a function reuse the Cosine Similarity
 measure to retrieve the documents which is the
nearest with vector q = 0 0 0.7 0.5 0 0.3 . Given the documents are represented as vectors.

nova galaxy heat actor film role


D1 1.0 0.5 0.3 0 0 0
D2 0.5 1.0 0 0 0 0
D3 0 1.0 0.8 0.7 0 0
D4 0 0.9 1.0 0.5 0 0
D5 0 0 0 1.0 0 1.0
D6 0 0 0 0 0.7 0
D7 0.5 0 0.7 0 0 0.9
D8 0 0.6 0 1.0 0.3 0.2

Anh H. Vo - [email protected] 3

You might also like