<jupyter_start><jupyter_text>Plotting Vectors<jupyter_code>plt.quiver(0,0,3,4)
plt.show()
plt.quiver(0,0,3,4,scale_units='xy',angles='xy',scale=1)
plt.show()
plt.quiver(0,0,3,4,scale_units='xy',angles='xy',scale=1)
plt.xlim(-10,10)
plt.ylim(-10,10)
plt.show()
plt.quiver(0,0,3,4,scale_units='xy',angles='xy',scale=1,color='r')
plt.quiver(0,0,-3,4,scale_units='xy',angles='xy',scale=1,color='g')
plt.xlim(-10,10)
plt.ylim(-10,10)
plt.show()
!pip install matplotlib
def plot_vectors(vecs):
  colors =['r','b','g','y']
  i=0
  for vec in vecs:
    plt.quiver(vec[0],vec[1],vec[2],vec[3],scale_units='xy',angles='xy',scale=1,color=colors[i%len(colors)])
    i += 1
    print(i)
  plt.xlim(-10,10)
  plt.ylim(-10,10)  
  plt.show()
plot_vectors([(0,0,3,4),(0,0,-3,4),(0,0,-3,-2),(0,0,4,-1)])<jupyter_output>1
2
3
4<jupyter_text>Vector Addition and Subtraction<jupyter_code>vecs = [(0,0,3,4),(0,0,-3,4),(0,0,-3,-2),(0,0,4,-1)]
plot_vectors([vecs[0],vecs[3]])
vecs[0]+vecs[1]
vecs = [np.asarray([0,0,3,4]),np.asarray([0,0,-3,4]),np.asarray([0,0,-3,-2]),np.asarray([0,0,4,-1])]
plot_vectors([vecs[0],vecs[3]])
vecs[0]+vecs[3]
plot_vectors([vecs[0],vecs[3],vecs[0]+vecs[3]])
print(vecs[0]+vecs[2])
plot_vectors([vecs[0],vecs[2],vecs[0]+vecs[2]])
print(vecs[0]+vecs[1])
plot_vectors([vecs[0],vecs[1],vecs[0]+vecs[1]])
#adding vector to itself where its going to have twice the magnitude
print(vecs[0]+vecs[0])
plot_vectors([vecs[0],vecs[0],vecs[0]+vecs[0]])
print(vecs[0]-vecs[3])
plot_vectors([vecs[0],vecs[3],vecs[0]-vecs[3]])
print(vecs[0]+(-vecs[3]))
plot_vectors([vecs[0],-vecs[3],vecs[0]+(-vecs[3])])
print(-vecs[0]+(vecs[3]))
plot_vectors([-vecs[0],vecs[3],-vecs[0]+(vecs[3])]) #commutative<jupyter_output>[ 0  0  1 -5]
1
2
3<jupyter_text>Vector Dot Product<jupyter_code>vecs = [np.asarray([0,0,3,4]),np.asarray([0,0,-3,4]),np.asarray([0,0,-3,-2]),np.asarray([0,0,4,-1])]
plot_vectors(vecs)
a = np.asarray([3,4])
b = np.asarray([4,-1])<jupyter_output><empty_output><jupyter_text>$\vec{a}\cdot\vec{b}=|\vec{a}| |\vec{b}| \cos(\theta)=a_xb_x + a_y b_y$<jupyter_code>a_dot_b = np.dot(a,b)
print(a_dot_b)<jupyter_output>8<jupyter_text>$a_b = |\vec{a}| \cos(\theta) = |\vec{a}|\frac{\vec{a}\cdot\vec{b}}{|\vec{a}| |\vec{b}|} = \frac{\vec{a}\cdot\vec{b}}{|\vec{b}|}$<jupyter_code>a_b = np.dot(a,b)/np.linalg.norm(b)
print(a_b)<jupyter_output>1.9402850002906638<jupyter_text>Unit vector along direction b$\vec{a_b} = a_b \hat{b} = a_b \frac{\vec{b}}{|\vec{b}|}$<jupyter_code>vec_a_b = (a_b/np.linalg.norm(b))*b
print(vec_a_b)
plot_vectors([np.asarray([0,0,3,4]),np.asarray([0,0,4,-1]),np.asarray([0,0,1.88235294, -0.47058824])])
#TODO projection of b on a
a = np.asarray([3,4])
b = np.asarray([-3,-2])
a_dot_b = np.dot(a,b)
print(a_dot_b)
#vectors with large obtuse angle gives negative values<jupyter_output>-17
{'fraction_non_alphanumeric': 0.27587437544610993, 'fraction_numerical': 0.0835117773019272, 'mean_word_length': 8.698961937716263, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '231807', 'license': 'Apache-2.0', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1426, 'n_words': 134, 'path': '0216_Vectors.ipynb', 'repo_name': 'yuvaraj119/Colab-Notebooks', 'size': '2802'}