Quiz 1

For Penn State student, access quiz here

import ipywidgets as widgets

Question 1

Consider three sets

\[ A_1=\{(x,y)\in R^2:x^2+y^2\le \frac{1}{4}\}, \quad A_2=\{(x,y)\in R^2:(x-\frac{1}{2})^2+y^2\le \frac{1}{4}\} \]

and \(A_3=\{(x,y)\in R^2:(x-\frac{3}{2})^2+y^2\le \frac{1}{4}\}\)

Which two sets are linearly separable ?

Question 2

Consider three sets \(A_1,A_2,A_3\subset R^d\), and three sentences listed below

-A: \(A_1,A_2,A_3\) are all-vs-one linearly separable.

-B: \(A_1,A_2,A_3\) are  linearly separable.

-C: \(A_1,A_2,A_3\) are pairwise linearly separable.

Which sentence implies other sentence ?

Question 3

Let

\[\begin{split} \boldsymbol a= \begin{bmatrix} 1\\ 1\\ 1\\ \vdots\\ 1 \end{bmatrix} \in R^n, A=\boldsymbol a\boldsymbol a^T \end{split}\]

Compute the eigenvalues and corresponding eigenvectors of \(A\). Write out solution

Question 4

Determine the global minimizer and the global minimum of the function \(f(x,y)=e^{(x-2)^2+y^2+2x^2+2xy+2(y-4)^2+4y-16x} \)

Question 5

Let

\[\begin{split} \boldsymbol x\in R^3, A=\left[ \begin{matrix} 1&2&3\\ 0&4&1\\ -1&-1&3 \end{matrix} \right]\in R^{3\times 3} \end{split}\]

Compute the Hessian matrix of the multivariable function \(f(\boldsymbol x)=\frac{1}{2} \boldsymbol x^TA \boldsymbol x.\)

Question 6

To define

\[\begin{split} A= \begin{bmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{bmatrix} \end{split}\]

what Python code should you use ?

Question 7

How to define a function \(f(x,y)=x^2+y\)

Question 8

What is the output of the following code:

salary = 8000

def printSalary(salary):
    if salary < 10000:
        salary = 10000
    else:
        print("Salary:", salary)
  
printSalary(salary)
print("Salary:", salary)
Salary: 8000

Question 9

What are the outputs of the following code?

str = "pynative"
print (str[1:3])
yn

Question 10

What are the outputs of the following code?

def my_sort(nums):
    count=0
    for i in range(len(nums)-1):
        for j in range(i+1,len(nums)):
            if nums[j] > nums[i]:
                count = count+1
                num_temp = nums[j]
                nums[j] = nums[i]
                nums[i] = num_temp
    print('The number of swap operation is',count)
    return nums
list_of_nums = [5, 1, 2, 8, 4]
print(my_sort(list_of_nums))
The number of swap operation is 6
[8, 5, 4, 2, 1]