We now present Berkeley's CS C151 Diagnostic Quiz.
We will solve it together in Google Colab for tomorrow.
This week's deliverable will have two parts:
Here's how you put together the first.
This is the answer to the first question:
The answer to the second question is:1. What is the magnitude of $2 - \sqrt{2}i$? Answer: By definition $|a + bi| = \sqrt{a^2+b^2}$. In our case $a = 2$ and $b=-\sqrt{2}$. So $|2-\sqrt{2}i| = \sqrt{2^2+(-\sqrt{2})^2} = \sqrt{4+2} = \sqrt{6}.$
Here now is the answer to the third question:Question 2. What is the complex conjugate of $e^{\frac{\pi i}{3}}$? Answer: For every complex number $z = a + bi$ we have * $z = a +ib = r e^{i\theta} = r (\cos{\theta} + i \sin{\theta})$ * where $r = |z| = \sqrt{a^2 + b^2}$ and $\tan{\theta}=\frac{b}{a}$ So for $e^{\frac{\pi i}{3}}$ we have $r = 1$ and $\theta = \frac{\pi}{3}$ which means $z = \cos{\frac{\pi}{3}} + i \sin{\frac{\pi}{3}} = \frac{1}{2} + i \frac{\sqrt{3}}{2}$. The complex conjugate of a complex number $z = a + i b$ is $z^* = a - i b$. So the answer to our question is: $\frac{1}{2} - i \frac{\sqrt{3}}{2}$.
We can start answering the fourth question as follows:Question 3. Compute $\begin{pmatrix} -1 & 1 \\ 3 & -1 \end{pmatrix} \cdot \begin{pmatrix} 0 & 1 \\ 2 & 0 \end{pmatrix} $ Answer: $\begin{pmatrix} -1 \cdot 0 + 1 \cdot 2 & -1 \cdot 1 + 1 \cdot 0 \\ 3 \cdot 0 + (-1) \cdot 2 & 3 \cdot 1 + (-1) \cdot 0 \end{pmatrix} = \begin{pmatrix} 2 & -1 \\ -2 & 3\end{pmatrix}$
Here's theQuestion 4. For each pair of matrices indicate if they commute. (Matrices $A$ and $B$ are said to commute if $AB = BA$). (a) $A = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \textrm{and} B = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} $ Second matrix is the identity so the answer here is: yes (here, $AB = BA = A$). (b) $\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \textrm{and} \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} $ Here $AB = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} \ne \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix} = BA$ so the answer is: no. We can multiply by hand, via Wolfram Alpha or using Python (numpy).
numpy
code that proves our last point: So we can now finish the answer to the fourth question as follows:import numpy as np A = np.matrix([[0, 1], [1, 0]]) B = np.matrix([[1, 0], [0, -1]]) print(np.dot(A, B)) print(np.dot(B, A))
To answer questions 5 and 6 we write:(c) $A = \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \textrm{and}~B = \begin {pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}$ Answer: I will let you prepare the answer for this one. (d) $A = \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \textrm{and}~B = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}$ Answer: second matrix is the identity here. (e) $A = \begin{pmatrix} 2 & 0 \\ 0 & -1 \end{pmatrix} \textrm{and}~B= \begin{pmatrix} 3 & 0 \\ 0 & 2 \end{pmatrix}$ Answer: Two diagonal matrices always commute. Please let me know though what the value of $AB$ is and how you calculated it.
Here's the code that solves the system in Python for question 6:Question 5: What is (i.e., determine) a unit vector in $\mathbb{R}^2$ that makes a $\frac{\pi}{4}$ angle with both the $x$- and $y$-axes? Answer: $r = 1$ and $\theta=\frac{\pi}{4}$ so $z = \cos{\frac{\pi}{4}}+i\sin{\frac{\pi}{4}} = \frac{\sqrt{2}}{2} + i \frac{\sqrt{2}}{2}$. We can also write this as $\begin{pmatrix} \frac{1}{\sqrt{2}}\\[0.5ex] \frac{1}{\sqrt{2}} \end{pmatrix}$. Question 6:What is a real unit vector in $\mathbb{R}^2$ orthogonal to $\begin{pmatrix} \frac{1}{\sqrt{3}}\\[0.5ex] \frac{\sqrt{2}}{\sqrt{3}} \end{pmatrix}$? Answer: we need to determine a vector $\begin{pmatrix} a\\[0.5ex] b \end{pmatrix}$ such that \begin{cases} \frac{a}{\sqrt{3}}+ \frac{{b\sqrt{2}}}{\sqrt{3}} = 0 \\ a^2 + b^2 = 1\end{cases} The first condition is the orthogonality the second that it's a unit vector. We can solve this by hand, in Wolfram Alpha or in Python. An answer is: $\begin{pmatrix} \frac{\sqrt{2}}{\sqrt{3}}\\[0.5ex] -\frac{1}{\sqrt{3}} \end{pmatrix}$
You can tell there are two possible answers.from sympy import * a, b = symbols('a, b') eq1 = Eq(a/sqrt(3)+b*sqrt(2)/sqrt(3), 0) eq2 = Eq(a**2+b**2, 1) sol = solve([eq1, eq2], [a, b]) print(sol)
Questions 7 and 8 can be addressed as follows:
Let's do this inQuestion 7: What is the inner product between the vectors $\begin{pmatrix} \frac{\sqrt{3}}{2}\\[0.5ex] \frac{1}{2} \end{pmatrix} \textrm{and} \begin{pmatrix} \frac{1}{2}\\[0.5ex] \frac{\sqrt{3}}{2} \end{pmatrix}$ ? The inner product is the sum of products of the corresponding elements: We calculate as follows from the given vectors $\frac{\sqrt{3}}{2} \cdot \frac{1}{2} + \frac{1}{2} \cdot \frac{\sqrt{3}}{2} = 2 \cdot \frac{\sqrt{3}}{4} = \frac{\sqrt{3}}{2}$ Question 8. And what is the angle between the two vectors in degrees? To calculate the cosine of the angle between two vectors in a 2D space: * Find the dot product of the vectors. * Divide the dot product by the magnitude of the first vector. * Divide the resultant by the magnitude of the second vector So here $\cos{\theta} = \frac{\frac{\sqrt{3}}{2}}{(\frac{3}{4} + \frac{1}{4}) (\frac{1}{4} + \frac{3}{4})} = \frac{\sqrt{3}}{2}$ so $\theta = 30^\circ$.
numpy
just for the fun of it: Here we used the fact that the vectors already had magnitude 1.v1 = np.array([[np.sqrt(3)/2], [1/2]]) v2 = np.array([[1/2], [np.sqrt(3)/2]]) inner_result = np.vdot(v1, v2) print(inner_result) np.degrees(np.arccos(inner_result))
So we're now left with just the last two problems:
Solve this by typing the following in Wolfram Alpha:Problem 9: Determine the eigenvalues of the matrix $ \begin{pmatrix} 0&1\\ 1&0 \end{pmatrix} $ Answer: $-1, 1$ Problem 10: Determine the eigenvector corresponding to the largest eigenvalue of the above matrix. What other eigenvectors does the matrix have? Answer: $\begin{pmatrix} \frac{1}{\sqrt{2}}\\[0.5ex] \frac{1}{\sqrt{2}} \end{pmatrix}$ and $\begin{pmatrix} -\frac{1}{\sqrt{2}}\\[0.5ex] \frac{1}{\sqrt{2}} \end{pmatrix}$
Likewise we can solve witheigenvalues and eigenvectors of [[0, 1],[1, 0]]
numpy
in Python:
Why the difference?a = np.matrix([[0, 1], [1, 0]]) eva, eve = np.linalg.eig(a) print(eva) print(eve)
Answer: the vectors need to be normalized.
More to come soon.