<a href="https://colab.research.google.com/github/maiormarso/AB-Demo/blob/master/module1_linear_algebra_review_LS_DS9_131_Linear_Algebra_Assignment.ipynb" target="_parent"></a>

# Part 1 - Scalars and Vectors

For 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


```
import math
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import numpy as np

# Vector Examples 

blue = [.2, 5]
red = [.1, .3]

#plt.arrow(0, 0, yellow[0], yellow[1], head_width=.02, head_length=0.01, color = 'y')
plt.arrow(0, 0, .2, .5, head_width=.02, head_length=0.01, color = 'b')
plt.arrow(0, 0, .1, .3,  head_width=.02, head_length=0.01, color = 'r')
plt.show()
```

## 1.2 Create a three-dimensional vecor and plot it on a graph


```
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

yellow = [.4, .5, .5]
red = [.2, .4, .0]
blue = [.9, .3, .3]

vectors = np.array([[0, 0, 0, .5, .5, .5], 
                    [0, 0, 0, .2, .1, .0],
                    [0, 0, 0, .1, .3, .3]])

X, Y, Z, U, V, W = zip(*vectors)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.quiver(X, Y, Z, U, V, W, length=1)
ax.set_xlim([0, 1])
ax.set_ylim([0, 1])
ax.set_zlim([0, 1])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
```

## 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? 


```
from math import e, pi
print(e)
print(pi)
```

    2.718281828459045
    3.141592653589793



```
import math
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import numpy as np

blue   = [.1, .3]#
blue_pi = [i*pi for i in blue]
blue_e  = [i*e for i in blue]
blue_5  = [i*5 for i in blue]

red   = [.2, .5]#
red_pi = [i*pi for i in red]
red_e  = [i*e for i in red]
red_5  = [i*5 for i in red]

plt.arrow(0, 0, blue[0], blue[1], head_width=.02, head_length=0.01, color = 'b')
plt.arrow(0, 0, blue_pi[0], blue_pi[1],  head_width=.02, head_length=0.01, color = 'b')
plt.arrow(0, 0, blue_e[0], blue_e[1],  head_width=.02, head_length=0.01, color = 'b')
plt.arrow(0, 0, blue_5[0], blue_5[1],  head_width=.02, head_length=0.01, color = 'b')

plt.arrow(0, 0, red[0], red[1], head_width=.02, head_length=0.01, color = 'r')
plt.arrow(0, 0, red_pi[0], red_pi[1],  head_width=.02, head_length=0.01, color = 'r')
plt.arrow(0, 0, red_e[0], red_e[1],  head_width=.02, head_length=0.01, color = 'r')
plt.arrow(0, 0, red_5[0], red_5[1],  head_width=.02, head_length=0.01, color = 'r')
plt.title('Scale vectors in 1.1 by 5,π,and −e')
plt.show()
```


```

```

## 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}


```
import math
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import numpy as np


red = [5, 7]
blue = [3, 4]


plt.arrow(0, 0, 5, 7, head_width=.02, head_length=0.01, color = 'r')
plt.arrow(0, 0, 3, 4,  head_width=.02, head_length=0.01, color = 'b')
plt.title('Vector Examples')
plt.show()
```

## 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}$


```
import math
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import numpy as np


red = [5, 7]
blue = [3, 4]
sub  =[2, 3]

plt.arrow(0, 0, 5, 7, head_width=.02, head_length=0.01, color = 'r')
plt.arrow(0, 0, 3, 4,  head_width=.02, head_length=0.01, color = 'b')
plt.arrow(0, 0, 2, 3, head_width=.02, head_length=0.01, color = 'g')
plt.title('Vector Examples')
plt.show()
```

## 1.6 Find $c \cdot d$ $Dot Product$

\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}



```
# a.b = (7)(12) + (22)(6) + (4)(2) + (16)(9)
84 + 132 + 8 + 144
```




    368



##  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}


```
# cross product
#[5,7,2],[3,4,6]
[7*6-2*4]-[5*6-2*3]+[5*4-7*3] # crossproduct
[34, -24,  -1]
```

#Norm of a Vector (Magnitude or length)
## 1.8 Find $||g||$ and then find $||h||$. Which is longer?

\begin{align}
\vec{g} = \begin{bmatrix} 1 \\ 1 \\ 1 \\ 8 \end{bmatrix}
\qquad
\vec{h} = \begin{bmatrix} 3 \\3 \\ 3 \\ 3 \end{bmatrix}
\end{align}


```
g=math.sqrt((1)^2 + (1)^2 + (1)^2 + (8)^2)
h=math.sqrt((3)^2 + (3)^2 + (3)^2 + (3)^2)
print(g,h)
```

    3.0 2.0


###g is longer

# Part 2 - Matrices


```
mn * np -> mp
CA, CD 
```

## 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}
\qquad
B = \begin{bmatrix}
2 & 4 & 6 \\
\end{bmatrix}
\qquad
C = \begin{bmatrix}
9 & 6 & 3 \\
4 & 7 & 11
\end{bmatrix}
\qquad
D = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
\qquad
E = \begin{bmatrix}
1 & 3 \\
5 & 7
\end{bmatrix}
\end{align}

## 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?


```
# CD     [[9 6 3  4 7 11]] * [[1 0 0  0 1 0  0 0 1 ]]

# [(9*1)+(6*0)+(3*0)   (9*0)+(6*1)+(3*0)   (9*0)+(6*0)+(3*1) ] 
# [(4*1)+(7*0)+(11*0)  (4*0)+(7*1)+(11*0)  (4*0)+(7*0)+(11*1)]
#   (9) + (0) + (0)     (0)  +(6) + (0)     (0) + (0) +  (3)
#   (4) + (0) + (0)     (0)  +(7) + (0)     (0) + (0) + (11)

#   [13 + 13 + 14] 
```


```
# AE   [1 5   3 7] [ 1 2  3 4  5 6]
#      1*1 3*2 5*1 7*2
#      1*3 3*4 5*4 7*4
#      2*5 3*6 5*6 7*6
#      1 +  6 +  6 +  9
#      4 + 12 + 20 + 28
#     10 + 18 + 30 + 42

#    [[15  36
#      56  79]] 
```




    186



## 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}


```
20 16 12 8 4
19 15 11 7 3
18 14 10 6 2
17 13  9 5 1
```

# 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}


```

```

## 3.2 Find $|H|$ and then find $|J|$.

\begin{align}
H= 
\begin{bmatrix}
12 & 11 \\
7 & 10 
\end{bmatrix}
\qquad
J= 
\begin{bmatrix}
0 & 1 & 2 \\
7 & 10 & 4 \\
3 & 2 & 0
\end{bmatrix}
\end{align}



```

```

## 3.3 Find $H^{-1}$ and then find $J^{-1}$


```

```

## 3.4 Find $HH^{-1}$ and then find $J^{-1}J$. Is $HH^{-1} == J^{-1}J$? Why or Why not?


```
inverse 
```

# Stretch Goals: 

A reminder that these challenges are optional. If you finish your work quickly we welcome you to work on them. If there are other activities that you feel like will help your understanding of the above topics more, feel free to work on that. Topics from the Stretch Goals sections will never end up on Sprint Challenges. You don't have to do these in order, you don't have to do all of them. 

- Write a function that can calculate the dot product of any two vectors of equal length that are passed to it.
- Write a function that can calculate the norm of any vector
- Prove to yourself again that the vectors in 1.9 are orthogonal by graphing them. 
- Research how to plot a 3d graph with animations so that you can make the graph rotate (this will be easier in a local notebook than in google colab)
- Create and plot a matrix on a 2d graph.
- Create and plot a matrix on a 3d graph.
- Plot two vectors that are not collinear on a 2d graph. Calculate the determinant of the 2x2 matrix that these vectors form. How does this determinant relate to the graphical interpretation of the vectors?



32518004ef199374122bff8748ab0beff1a8dcd9
ipynb
Jupyter Notebook
module1_linear_algebra_review_LS_DS9_131_Linear_Algebra_Assignment.ipynb
maiormarso/AB-Demo
bad3110eb80baf3b00ac7b6f17f0c593b1d0e3b8
MIT
module1_linear_algebra_review_LS_DS9_131_Linear_Algebra_Assignment.ipynb
maiormarso/AB-Demo
bad3110eb80baf3b00ac7b6f17f0c593b1d0e3b8
MIT
module1_linear_algebra_review_LS_DS9_131_Linear_Algebra_Assignment.ipynb
maiormarso/AB-Demo
bad3110eb80baf3b00ac7b6f17f0c593b1d0e3b8
MIT
Qwen/Qwen-72B
1. YES
2. YES