Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Introduction to Data Science, Fall 2022

Exercise 3:

3. 1) Write a python program to calculate p-norm() with the parameters: input vector x and order p

a) Input a vector x= (-ID,ID) in your p-norm function, p ={0, 1, 2, 5, 10} and compare with built-in
function in library numpy.linalg.norm()

b) Using numpy.linspace() to generate 10 values of x1 from [-ID,ID] where ID is your last number in
student ID, if it is ID = 0 you can use 1. Then, write a function to calculate x2 such as norm_p(x): Lp(x) =
ID where p = {0, 1, 2, 5, 10}. Thus, we have 20 points x = (x1, x2).

 Plot all points x for p = {0, 1, 2, 5, 10} and get similar image to this example.
 Increase more number of points to make more beautiful (smoother).

3. 2) Write a python function to calculate inner product of <x, y> check it is equal to the results of
numpy.dot()

3.3) Projection:

a) Write a projection function into 1D, b=(1,1) that used projection matrix (slide 24 Lecture 3). Test this
function with 10 points (x,y) = {random (-ID, ID), random(-ID, ID)}.

b) Plot 10 points in blue color then projected points in red color.

c) Use the projection function in 3.3.a) to write a python function for Gram-Schmidt Orthogonalization
method with the example in the slide. Apply for example in slide 27 Lecture 3.

3.4) Write a rotation function take angle θ. Using numpy.linspace() to generate 10 values of x from [-
ID,ID], 10 values of y from [-ID,ID], where ID is your last number in student ID, if it is ID = 0 you can use
1. Then, we could create 100 data points such as pairs (x,y) = (x[i], y[j]) for i, j= 0,…,9.

Transform these 100 points and plot them with 4 colors in exercise 2b.

Share the Fullname_StudentID_3.ipynb file link and SUBMIT the link to the elearning website
before 23/09/2022.

You might also like