0% found this document useful (0 votes)
32 views2 pages

Lab 1

This document provides a set of exercises on vectors and linear algebra. It includes exercises to create vectors with various elements and methods, perform operations on vectors like taking subsets and reversing order, and calculate values from vectors like maximum, minimum, mean and median.
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)
32 views2 pages

Lab 1

This document provides a set of exercises on vectors and linear algebra. It includes exercises to create vectors with various elements and methods, perform operations on vectors like taking subsets and reversing order, and calculate values from vectors like maximum, minimum, mean and median.
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/ 2

Ton Duc Thang University

Faculty of Information Technology

Lab 2
APPLIED LINEAR ALGEBRA FOR IT - 501032

1 Exercises
Exercise 1: Write a command
 to create vectors and get
 the number of elements in each vector. x =
1 3 5 2 9 and y = −1 3 15 27 29

Exercise 2: Write a command to create the following vectors with n elements (user-defined variable)

(a) b = 12 14 16 18 20 22 24 26 28 30 32 ...

(b) c = 31 33 35 37 39 41 43 45 47 49 51 ...

(c) x = ... −5 −4 −3 −2 −1 0 1 2 3 4 5 ...

(d) y = ... 5 4 3 2 1 0 −1 −2 −3 −4 −5 ...

(e) z = 10 8 6 4 2 0 −2 −4
 
1 1 1 1 1 1 1
(f) w = 1 ...
2 4 8 16 32 64 128
 
1 1 1 1 1 1
(g) d = 1 1 ...
2 3 5 8 13 21
 
1 1 1 1 1 1 1 1 1
(h) e = ...
2 3 5 7 11 13 17 19 23

(i) a = 1 3 6 10 15 21 28 36 ...
 
1 1 1 1
(j) n = ...
2 5 10 17
 
1 2 3 4
(k) p = 0 ...
2 3 4 5
(l) Create o vector that contains the characters from ’a’ to ’z’
(m) Create s vector that contains the characters 0 A0 0 D0 0 G0 0 J 0 ...


Exercise 3: Write a command to create the following vector by logarithmic spacing method
x = 101 102 103 104 105 ... 10n


 
Exercise 4: Let two vectors x = 1 2 3 and y = 98 12 33 . Write a command to create a
vector z = 1 2 3 98 12 33 from x and y.
 
Exercise5: Let twovectors x = 1 2 3 and y = 4 5 6 . Write a command to create a vector
1 2 3
z=
4 5 6

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


Exercise 6: Let x = 0 2 4 6 8 10 12 14 16 18 20 . Write a command to perform the
following:

(a) Take the first sixth elements in the vector x


(b) Take the last fifth elements in the vector x
(c) Take the first, fourth, and last elements in the vector x
(d) Take the first, third, fifth, and seventh elements in the vector x
(e) Take the elements with the odd indices in the vector x
(f) Take the elements with the even indices in the vector x

Exercise 7: Let x = 3 11 −9 −131 −1 1 −11 91 −6 407 −12 −11 12 153 371

(a) Find the maximize in the vector x.


(b) Find the minimize in the vector x.
(c) Find the index of the values of x that are greater than 10.
(d) Write command to reverse x vector.
(e) Write command to sort x vector in ascending order.
(f) Write command to sort x vector in descending order.
(g) Write command to count how many times have that xi + xj = 0, (i 6= j).
(h) Write command to count total number of duplicate elements in x vector.
(i) Write command to create a new y vector which yi = xi + xn−i−1 , where n is the length of x
vector.
(j) Write command to create a new w vector which contains Armstrong/ Narcissistic numbers in x
vector.

Hint: Definition of Armstrong/ Narcissistic number: a given number base b is a number


that is the sum of its own digits each raised to the power of the number of digits. For example,
the number 153 in base b = 3 is a Narcissistic number, because b = 3 and 153 = 13 + 53 + 33

(k) Write command to delete all negative numbers in x vector.


(l) Write command to find median value in x vector.
(m) Write command to calculate the sum of all values which are less than mean value in x vector.
(n) Write command to create a new vector which each negative value is replaced by its absolute value.

Anh H. Vo - [email protected] 2

You might also like