<jupyter_start><jupyter_text>Part 1 - Scalars and VectorsFor the questions below it is not sufficient to simply provide answer to the questions, but you must solve the problems and show your work using python (the NumPy library will help a lot!) Translate the vectors and matrices into their appropriate python  representations and use numpy or functions that you write yourself to demonstrate the result or property.   1.1 Create a two-dimensional vector and plot it on a graph<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
vector = np.array([1,6])
plt.arrow(0, 0, *vector, head_width=.1, head_length=0.1)
plt.xlim(0,max(vector)+1)       
plt.ylim(0,max(vector)+1);<jupyter_output><empty_output><jupyter_text>1.2 Create a three-dimensional vecor and plot it on a graph<jupyter_code>from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

vector = np.array([3, 2, 3])

ax.quiver(*(0,0,0), *vector)
ax.set_xlim([0, max(vector) + 1])
ax.set_ylim([0, max(vector) + 1])
ax.set_zlim([0, max(vector) + 1])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show();<jupyter_output><empty_output><jupyter_text>1.3 Scale the vectors you created in 1.1 by $5$, $\pi$, and $-e$ and plot all four vectors (original + 3 scaled vectors) on a graph. What do you notice about these vectors?<jupyter_code>vector = np.array([1,6])
quiver = np.array([vector, vector*5, vector*np.pi, vector*-np.exp(1)])

for v in quiver:
    plt.arrow(0, 0, *v, head_width=1, head_length=1)
    
plt.xlim(quiver.min()-1,quiver.max()+1)       
plt.ylim(quiver.min()-1,quiver.max()+1);<jupyter_output><empty_output><jupyter_text>1.4 Graph vectors $\vec{a}$ and $\vec{b}$ and plot them on a graph\begin{align}\vec{a} = \begin{bmatrix} 5 \\ 7 \end{bmatrix}\qquad\vec{b} = \begin{bmatrix} 3 \\4 \end{bmatrix}\end{align}<jupyter_code>a = np.array([5, 7])
b = np.array([3, 4])
quiver = np.array([a, b])

for v in quiver:
    plt.arrow(0, 0, *v, head_width=0.5, head_length=0.5)
    
plt.xlim(0,quiver.max()+1)       
plt.ylim(0,quiver.max()+1);<jupyter_output><empty_output><jupyter_text>1.5 find $\vec{a} - \vec{b}$ and plot the result on the same graph as $\vec{a}$ and $\vec{b}$. Is there a relationship between vectors $\vec{a} \thinspace, \vec{b} \thinspace \text{and} \thinspace \vec{a-b}$<jupyter_code>a = np.array([5, 7])
b = np.array([3, 4])
quiver = np.array([a, b, a-b])

for v in quiver:
    plt.arrow(0, 0, *v, head_width=0.5, head_length=0.5)
    
plt.xlim(0,quiver.max()+1)       
plt.ylim(0,quiver.max()+1);<jupyter_output><empty_output><jupyter_text>$\vec{a-b}$ is the length and direction connecting the tips of $\vec{a}$ and $\vec{b}$  1.6 Find $c \cdot d$\begin{align}\vec{c} = \begin{bmatrix}7 & 22 & 4 & 16\end{bmatrix}\qquad\vec{d} = \begin{bmatrix}12 & 6 & 2 & 9\end{bmatrix}\end{align}<jupyter_code>np.dot(np.array([ 7, 22,  4, 16]),
       np.array([12,  6,  2,  9]))<jupyter_output><empty_output><jupyter_text>1.7 Find $e \times f$\begin{align}\vec{e} = \begin{bmatrix} 5 \\ 7 \\ 2 \end{bmatrix}\qquad\vec{f} = \begin{bmatrix} 3 \\4 \\ 6 \end{bmatrix}\end{align}<jupyter_code>np.cross(np.array([5, 7, 2]),
         np.array([3, 4, 6]))<jupyter_output><empty_output><jupyter_text>1.8 Find $||g||$ and then find $||h||$. Which is longer?\begin{align}\vec{e} = \begin{bmatrix} 1 \\ 1 \\ 1 \\ 8 \end{bmatrix}\qquad\vec{f} = \begin{bmatrix} 3 \\3 \\ 3 \\ 3 \end{bmatrix}\end{align}<jupyter_code>(np.linalg.norm(np.array([1, 1, 1, 8])), 
 np.linalg.norm(np.array([3, 3, 3, 3])))<jupyter_output><empty_output><jupyter_text>1.9 Show that the following vectors are orthogonal (perpendicular to each other):\begin{align}\vec{g} = \begin{bmatrix} 1 \\ 0 \\ -1  \end{bmatrix}\qquad\vec{h} = \begin{bmatrix} 1 \\ \sqrt{2} \\ 1 \end{bmatrix}\end{align}<jupyter_code>np.dot(np.array([1,        0, -1]),
       np.array([1, 2**(1/2),  1]))<jupyter_output><empty_output><jupyter_text>Part 2 - Matrices  2.1 What are the dimensions of the following matrices? Which of the following can be multiplied together? See if you can find all of the different legal combinations.\begin{align}A = \begin{bmatrix}1 & 2 \\3 & 4 \\5 & 6\end{bmatrix}\qquadB = \begin{bmatrix}2 & 4 & 6 \\\end{bmatrix}\qquadC = \begin{bmatrix}9 & 6 & 3 \\4 & 7 & 11\end{bmatrix}\qquadD = \begin{bmatrix}1 & 0 & 0 \\0 & 1 & 0 \\0 & 0 & 1\end{bmatrix}\qquadE = \begin{bmatrix}1 & 3 \\5 & 7\end{bmatrix}\end{align}<jupyter_code>A = np.array([[1, 2],
              [3, 4],
              [5, 6]])

B = np.array([[2, 4, 6]])

C = np.array([[9, 6,  3],
              [4, 7, 11]])

D = np.array([[1, 0, 0],
              [0, 1, 0],
              [0, 0, 1]])

E = np.array([[1, 3],
              [5, 7]])

quiver = [A, B, C, D, E]

# You can multipy any two matrices where the number of columns of the first matrix 
# is equal to the number of rows of the second matrix.

for M1 in quiver:
    for M2 in quiver:
        if M1 is M2:
            continue
        if M1.shape[1] == M2.shape[0]:
            print('Can multiply:', M1, M2, sep='\n')
            print('\n')
        if M1.shape[0] == M2.shape[1]:
            print('Can multiply:', M2, M1, sep='\n')
            print('\n')<jupyter_output>Can multiply:
[[2 4 6]]
[[1 2]
 [3 4]
 [5 6]]


Can multiply:
[[1 2]
 [3 4]
 [5 6]]
[[ 9  6  3]
 [ 4  7 11]]


Can multiply:
[[ 9  6  3]
 [ 4  7 11]]
[[1 2]
 [3 4]
 [5 6]]


Can multiply:
[[1 0 0]
 [0 1 0]
 [0 0 1]]
[[1 2]
 [3 4]
 [5 6]]


Can multiply:
[[1 2]
 [3 4]
 [5 6]]
[[1 3]
 [5 7]]


Can multiply:
[[2 4 6]]
[[1 2]
 [3 4]
 [5 6]]


Can multiply:
[[2 4 6]]
[[1 0 0]
 [0 1 0]
 [0 0 1]]


Can multiply:
[[ 9  6  3]
 [ 4  7 11]]
[[1 2]
 [3 4]
 [5 6]]


Can multiply:
[[1 2]
 [3 4]
 [5 6]]
[[ 9  6  3]
 [ 4  7 11]]


Can multiply:
[[ 9  6  3]
 [ 4  7 11]]
[[1 0 0]
 [0 1 0]
 [0 0 1]]


Can multiply:
[[1 3]
 [5 7]]
[[ 9  6  3]
 [ 4  7 11]]


Can multiply:
[[1 0 0]
 [0 1 0]
 [0 0 1]]
[[1 2]
 [3 4]
 [5 6]]


Can multiply:
[[2 4 6]]
[[1 0 0]
 [0 1 0]
 [0 0 1]]


Can multiply:
[[ 9  6  3]
 [ 4  7 11]]
[[1 0 0]
 [0 1 0]
 [0 0 1]]


Can multiply:
[[1 2]
 [3 4]
 [5 6]]
[[1 3]
 [5 7]]


Can multiply:
[[1 3]
 [5 7]]
[[ 9  6  3]
 [ 4  7 11]]<jupyter_text>2.2 Find the following products: CD, AE, and BA. What are the dimensions of the resulting matrices? How does that relate to the dimensions of their factor matrices?<jupyter_code># the result of multiplying two matrices will have the shape of 
# the first matrix's rows and the second matrix's columns

CD = np.matmul(C, D)
print(CD)

AE = np.matmul(A, E)
print(AE)

BA = np.matmul(B, A)
print(BA)<jupyter_output>[[ 9  6  3]
 [ 4  7 11]]
[[11 17]
 [23 37]
 [35 57]]
[[44 56]]<jupyter_text>2.3  Find $F^{T}$. How are the numbers along the main diagonal (top left to bottom right) of the original matrix and its transpose related? What are the dimensions of $F$? What are the dimensions of $F^{T}$?\begin{align}F = \begin{bmatrix}20 & 19 & 18 & 17 \\16 & 15 & 14 & 13 \\12 & 11 & 10 & 9 \\8 & 7 & 6 & 5 \\4 & 3 & 2 & 1\end{bmatrix}\end{align}<jupyter_code>F = np.array([[20, 19, 18, 17],
              [16, 15, 14, 13],
              [12, 11, 10,  9],
              [ 8,  7,  6,  5],
              [ 4,  3,  2,  1]])
print(F)

print(np.transpose(F))<jupyter_output>[[20 19 18 17]
 [16 15 14 13]
 [12 11 10  9]
 [ 8  7  6  5]
 [ 4  3  2  1]]
[[20 16 12  8  4]
 [19 15 11  7  3]
 [18 14 10  6  2]
 [17 13  9  5  1]]<jupyter_text>Part 3 - Square Matrices  3.1 Find $IG$ (be sure to show your work) 😃\begin{align}G= \begin{bmatrix}12 & 11 \\7 & 10 \end{bmatrix}\end{align} The product of any square matrix with its corresponding identity matrix is the same martrix.   3.2 Find $|H|$ and then find $|J|$.\begin{align}H= \begin{bmatrix}12 & 11 \\7 & 10 \end{bmatrix}\qquadJ= \begin{bmatrix}0 & 1 & 2 \\7 & 10 & 4 \\3 & 2 & 0\end{bmatrix}\end{align}<jupyter_code>H = np.array([[12, 11],
              [ 7, 10]])
np.linalg.det(H)
J = np.array([[ 0, 1, 2],
              [ 7,10, 4],
              [ 3, 2, 0]])
np.linalg.det(J)<jupyter_output><empty_output><jupyter_text>3.3 Find $H^{-1}$ and then find $J^{-1}$<jupyter_code>np.linalg.inv(H)
np.linalg.inv(J)<jupyter_output><empty_output><jupyter_text>3.4 Find $HH^{-1}$ and then find $J^{-1}J$. Is $HH^{-1} == J^{-1}J$? Why or Why not?<jupyter_code>np.matmul(H, np.linalg.inv(H))
np.matmul(np.linalg.inv(J), J)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18917946257197696, 'fraction_numerical': 0.07701535508637236, 'mean_word_length': 3.174762143214822, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '56356', 'license': 'MIT', 'n_tokens_mistral': 3882, 'n_tokens_neox': 3436, 'n_words': 1024, 'path': '05-Linear-Algebra/01_Linear_Algebra_Assignment.ipynb', 'repo_name': 'shalevy1/data-science-journal', 'size': '8336'}