(Answer all questions -- do not spend more than 1 hour)
Each question carries 2 marks.
• A 1. Create a list of tuples containing the name and age of five imaginary friends .
• A2. Using (!) or otherwise, use a bash command to output the string , "This is a programming lab course!"
• A3. Define a recursive function for f (x) = x !, where X ! == I *2 * 3 * ... x and f (0) = 1. Print the output for f (10).
• A4. Using a single line statement, create a random 2 x 2 matrix A with elements between 0 and 5. You can include an additional import
statement.
• A5. Create a list from an array of 100 real numbers between 0 and 1. Extract the last five numbers.
• AG. Define a function that calculates the trace and determinant of a 2 x 2 matrix A, and returns a tuple at the output, i.e., output is (Tr(A) ,
det(A)).
Section 8
(Answer any 3 question -- do not spend more than 45 mins on each)
Each question carries 6 marks.
• 81. From linear algebra (and from elementary quantum mechanics), we know that all Hermitian matrices have real eigenvalues . However,
not all Hermitian matrices have positive eigenvalues (A; ~ 0, V i).
a) Write a function that checks if a random 2 x 2 matrix is Hermitian, both Hermitian and positive or neither. (3 Marks)
Hint: Use the numpy (as np) function np.round(x, 10) to round x to nearest 10 decimal points, and eliminate any small imaginary part that
remains due to numerical error. Moreover, the commands np.real and np.imag can be used to isolate real and imaginary parts. Use the
fact that for real eigenvalues, the imaginary part must be equal to 0.