Practice Question 2 - Vectors and Linear Functions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Practice Question 2: Vectors and Linear Functions

(some of the exercises are from the book: Vectors, Matrices and Least Squares (VMLS))

1. Consider two vectors u= [ 1, 2,−3 ] and v=[−1 ,2 ,5 ]


a. Draw the vectors in 3D space.
b. Draw the vector u−v and compute its coordinates.
c. Find the distance between the two points represented by the vectors u and v if these are
displacement vectors from the origin of the 3D space.
d. Find the coordinates of the midpoint of the line connecting u and v .

2. Exercise 1.11 and 1.13 from VMLS

3. Suppose the vector p contains the price of 5 items and q contains the quantity bought of the items.
Write the following functions in vector format (you can use only vector operations):

a. The average price of the items. [for example: if p= [ 10 , 20 ,30 , 40 , 50 ] then the
average_price = 30]
b. Sum of the total cost of the items bought. [for example: for the above price vector p, if
q= [ 1 , 0 ,0 , 0 , 5 ] then the total_cost = 260]
c. Difference between the quantity bought of the 1st and the 3rd item. [for example: if
q= [ 1 , 0 ,0 , 0 , 5 ] then the difference = 1]
d. Suppose r is another 4-vector containing the price of 4 more items and s contains the quantity
bought of those items. Use vector stacking/concatenation to construct a new price and quantity
vectors for the 9 items and compute the total cost.
e. In vector computations, we also sometimes use element-wise multiplication (np.multiply(u,v)
or u * v, for shorthand where u and v are same sized vectors). Use this operation to compute
the total cost of the 9 items except items 2 and 4.

4. Exercise 2.1 and 2.8* from VMLS

5. Consider an m x n matrix A and an n-vector x and y=f (x )= Ax (Ax means we are multiplying
the matrix A with vector x)

a. What is the size of the input (x) and output (y) of the function f(x)? The function can be
specified as f : R? → R? , what would you write in place of the ‘?’ marks?
b. Suppose all elements of the matrix A is 1, write in words what output will you get by passing
the x to the function?

[ ]
100
c. Suppose A = 0 0 1 , write in words what output you will get by passing a 3-vector x to the
010
function?

[]
1
d. Write down a matrix A that will convert the input vector x= 2 to the output vector
3

[]
3
y= 1 .
2
[]
y1
e. Write down the matrix A, that will produce the output vector y= y2 , such that
y3
y 1=x 1 + x 2 + x 3 , y 2 =2 x 1 +3 x 2 , y 3 =0.5 x 3 .

f. Observe, each of the y 1 , y 2 , y 3 are functions of x. That is


y 1=f 1 ( x) , y 2 =f 2 (x), y 3 =f 3 ( x) . Are these functions linear or not?

You might also like