Lecture 11.

Today we discuss and implement "Money or Tiger".

Below, five more problems from Linear Algebra section of The Highlights Quiz.


**Question 1.** Add vectors
$v = \begin{pmatrix} i \\ 2 \end{pmatrix}$
and $w = \begin{pmatrix} 3 \\ -100 \end{pmatrix}$.

See example 2.1 on page 32 in Martin LaForest.

See also below.

--

import numpy as np
v = np.array([[1j], [2]])
w = np.array([[3], [-100]])
print(v + w)
# in WolframAlpha just type: {{i}, {2}} + {{3}, {-100}}

--

**Question 2.**

Calculate $\begin{pmatrix} 3 & 3 & -1+2i \\ 1 & -3 & 0 \end{pmatrix} + \begin{pmatrix} 2 & -1 & i \\ 0 & 2 + 3i & -3\end{pmatrix}$

See example 2.4 on page 36 in Martin LaForest.

--

import numpy as np
a = np.array([[3, 3, -1+2j], [1, -3, 0]])
b = np.array([[2, -1, 1j], [0, 2+3j, -3]])
print(a + b)
# in WolframAlpha just type:
# {{3, 3, -1+2i}, {1, -3, 0}} + {{2, -1, i}, {0, 2+3i, -3}}

--

Question 3. First let's review how we can improve the output of these calculations.

--

import numpy as np
import sympy as sym
from IPython.display import display, Math
A = np.array([[12, 5, 2],
       [20, 4, 8],
       [ 2, 4, 3],
       [ 7, 1,10]])
A = sym.Matrix(A)
display(A)

--

a = np.array([[3, 3, -1+2j], [1, -3, 0]])
b = np.array([[2, -1, 1j], [0, 2+3j, -3]])
sum = a + b
display(sym.Matrix(sum))

--

Now let's calculate $2 \cdot \begin{pmatrix} 3 & 3 & -1 + 2i \\ 1 & -3 & 0 \end{pmatrix}$. 

See page 36 in Martin LaForest's document (example 2.4).

--

a = np.array([[3, 3, -1+2j], [1, -3, 0]])
result = 2 * a
display(sym.Matrix(result))
# in WolframAlpha just type:
# 2 * {{3, 3, -1+2i}, {1, -3, 0}}

--

**Question 4.** Calculate $\begin{pmatrix} 2 & 3 & i \\ 3 & -2 & 1 \end{pmatrix} \cdot \begin{pmatrix} 0 & 1 \\ 0 & 12 \\ 3 & -2 \end{pmatrix}$

See Definition 2.24 on page 36 and explanations on pp. 37, 38. 

This is Example 2.7 on page 39. Practice calculating by hand as explained.

--

a = np.array([[2, 3, 1j], [3, -2, 1]])
b = np.array([[0, 1], [0, 12], [3, -2]])
result = np.dot(a, b)
display(sym.Matrix(result))
# in WolframAlpha just type:
# {{2, 3, i}, {3, -2, 1}} * {{0, 1}, {0, 12}, {3, -2}}

--

**Question 5.** Calculate $\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \cdot \begin{pmatrix} 3 \\ 2 \end{pmatrix}$ 

This is Example 2.7 on page 39. 

--

a = np.array([[1, 0], [0, -1]])
b = np.array([[3], [2]])
result = np.dot(a, b)
display(sym.Matrix(result))
# in WolframAlpha just type:
# {{1, 0}, {0, -1}} * {{3}, {2}}

--

**Question 6.** Calculate $\begin{pmatrix} -1 & 0 \\ 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} v_1 \\ v_2 \end{pmatrix}$.

This is example 2.8 on pp. 39, 40 in Martin LaForest's booklet.

--

from sympy import symbols
v1, v2 = symbols('v1 v2')
a = np.array([[-1, 0], [0, 1]])
b = np.array([[v1], [v2]])
result = np.dot(a, b)
display(sym.Matrix(result))
# in WolframAlpha just type:
# {{-1, 0}, {0, 1}} * {{v1}, {v2}}

--

**Question 7.** If $M = \begin{pmatrix} 1 & 2 \\ 3 & 1 \end{pmatrix}$ and $N = \begin{pmatrix} 4 & 3 \\ 2 & 1 \end{pmatrix}$ calculate $MN$ and $NM$.

This is observation. 2.2.8 on page 40 in Martin LaForest's booklet.

--

M = np.array([[1, 2], [3, 1]])
N = np.array([[4, 3], [2, 1]])
mn = np.dot(M, N)
nm = np.dot(N, M)
display(sym.Matrix(nm))
print("---------")
display(sym.Matrix(mn))
# in WolframAlpha just type:
# {{1, 2}, {3, 1}} * {{4, 3}, {2, 1}}
# and then {{4, 3}, {2, 1}} * {{1, 2}, {3, 1}}

--

Type them in and see how they behave.