<a href="https://colab.research.google.com/github/StevenMElliott/AB-Demo/blob/master/Copy_of_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. 


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

## 1.1 Create a two-dimensional vector and plot it on a graph


```
v1 = [300,250]
plt.arrow(0,0, 300, 250, head_width=10, head_length=10, color='r');
plt.title('Red Vector')
plt.axis([0, 350, 0, 300]); #([-x, x, -y, y]) limits of the graph - BRACKETS
```

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


```
vectors = np.array( [[0,0,0,-1,-0,1]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for vector in vectors:
  v = np.array([vector[3],vector[4],vector[5]])
  vlength=np.linalg.norm(v)
  ax.quiver(vector[0], vector[1], vector[2], vector[3], vector[4], vector[5],
         pivot='tail',length=vlength,arrow_length_ratio=0.3/vlength)
ax.set_xlim([-3,3])
ax.set_ylim([-3,3])
ax.set_zlim([0,3]);
```

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


```
v1 = [300, 250]
v2 =[(300*5), (250*5)]
v3 = [(300*pi), (250*pi)]
v4 = [(300*-e), (250*-e)]
```


```
#the vectors and scalers
v1 = [300, 250]
v2 =[(300*5), (250*5)]
v3 = [(300*pi), (250*pi)]
v4 = [(300*-e), (250*-e)]

#plot the vectors
original = plt.arrow(0,0, v1[0], v1[1], head_width=100
                     , head_length=100, color='r');
scaled_by_5 = plt.arrow(0,0, v2[0], v2[1], head_width=100
                        , head_length=100, color='b');
scaled_by_pi = plt.arrow(0,0, v3[0], v3[1], head_width=100
                         , head_length=100, color='y');
scaled_by_neg_e = plt.arrow(0,0, v4[0], v4[1], head_width=100
                            , head_length=100, color='black');

#reference lings and limits
plt.grid()
plt.axhline(y=0, alpha=.5)
plt.axvline(x=0, alpha=.5)
plt.axis([-1600, 1600, -1600, 1600]);
```

These vectors are colinear

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


```
a = np.array([5,7])
b = np.array([3,4])
plt.arrow(0,0, a[0], a[1], head_width=.2, head_length=.2, color='r');
plt.arrow(0,0, b[0], b[1], head_width=.2, head_length=.2, color='b');

plt.axis([0,8,0,8]);
```

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


```
a = np.array([5,7])
b = np.array([3,4])
difference = a-b
plt.arrow(0,0, a[0], a[1], head_width=.2, head_length=.2, color='r');
plt.arrow(0,0, b[0], b[1], head_width=.2, head_length=.2, color='b');
plt.arrow(0,0, difference[0], difference[1], head_width=.2, head_length=.2, color='k');

print('The result is:',difference)
plt.axis([0,8,0,8]);c = a-b
```

The relationship is taking the values from the first and subtracting the values of the 2nd. The 3rd vector is equal to (2, 3)

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



```

```

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


```

```

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


```

```

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


```

```

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


```

```

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


```

```

# 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 $G^{-1}G$. Is $HH^{-1} == G^{-1}G$? Why or Why not?

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



69672eb47c255bfac5c45371e09ee621bf8cfe9d
ipynb
Jupyter Notebook
Copy_of_Linear_Algebra_Assignment.ipynb
StevenMElliott/AB-Demo
aa70681a7da90ff417872231aff883ad43a72efb
MIT
Copy_of_Linear_Algebra_Assignment.ipynb
StevenMElliott/AB-Demo
aa70681a7da90ff417872231aff883ad43a72efb
MIT
Copy_of_Linear_Algebra_Assignment.ipynb
StevenMElliott/AB-Demo
aa70681a7da90ff417872231aff883ad43a72efb
MIT
Qwen/Qwen-72B
1. YES
2. YES