<jupyter_start><jupyter_text>**Basics**<jupyter_code># import required packages

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>\begin{equation}u = \begin{pmatrix} x \\y\end{pmatrix}\end{equation}<jupyter_code># numpy array [a vector]
u = np.array([1,2])
# visualizing the vector on 2-dimentional co-ordinate system
x_coords, y_coords = u
plt.scatter(x_coords, y_coords, color=["r"])
plt.axis([0, 9, 0, 6])
plt.grid('on')
plt.show()
# function to plot vector
def plot_vector2d(vector2d, origin=[0, 0], **options):
    """
    plot a vector as arrow from origin to the given vector2d
    Args: vector2d
    returns: arrow plot
    """
    return plt.arrow(origin[0], origin[1], vector2d[0], vector2d[1],
              head_width=0.2, head_length=0.3, length_includes_head=True,
              **options)
plot_vector2d(u, color="b")
plt.scatter(x_coords, y_coords, color=["r"])

plt.axis([0, 9, 0, 6])
plt.grid('on')
plt.show()
u = np.array([0,2])
v = np.array([5,0])

plot_vector2d(u, origin=[0,0], color="b")
plot_vector2d(v, origin=[0,0], color="r")

x1,x2,y1,y2 = -5, 10, -5, 5
plt.axis([x1,x2,y1,y2])
plt.grid('on')
plt.show()<jupyter_output><empty_output><jupyter_text>**Rotation of 2-D vectors** \begin{equation}Rx = x{}^{'}\end{equation}\begin{equation}\begin{pmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta\end{pmatrix} \begin{pmatrix} x\\ y \end{pmatrix}=\begin{pmatrix} x{}^{'}\\ y{}^{'} \end{pmatrix} \end{equation}<jupyter_code>def rotate(th):
    "2-D rotational matrix"
    R = np.array([[np.cos(th), -1*np.sin(th)], [np.sin(th), np.cos(th)]])
    return R<jupyter_output><empty_output><jupyter_text>**Applying roatation on the vectors**<jupyter_code>th = np.pi/4
print(f'Ratation angle: \n {np.degrees(th)}')
R = rotate(th)
print(f'Rotational matrix:\n {np.round(R)}')
uR = (np.dot(u,R))
vR = (np.dot(v,R))
print(f'Rotated u: \n {uR}')
print(f'Rotated u: \n {vR}')<jupyter_output>Ratation angle: 
 45.0
Rotational matrix:
 [[ 1. -1.]
 [ 1.  1.]]
Rotated u: 
 [1.41421356 1.41421356]
Rotated u: 
 [ 3.53553391 -3.53553391]<jupyter_text>**Plotting the actual and roatated vectors**<jupyter_code>plot_vector2d(u, origin=[1,1], color="b", alpha=0.3)
plot_vector2d(v, origin=[0,0], color="r", alpha=0.3)

plot_vector2d(uR, origin=[1,1], color="b", alpha=1)
plot_vector2d(vR, origin=[0,0], color="r", alpha=1)

x1,x2,y1,y2 = -5, 10, -5, 5
plt.axis([x1,x2,y1,y2])
plt.grid('on')
plt.show()<jupyter_output><empty_output><jupyter_text>**Vector Addition**![alt text](https://mathinsight.org/media/image/image/vector_parallelogram_law.png)<jupyter_code>plot_vector2d(u, color="r")
plot_vector2d(v, color="b")
plot_vector2d(v, origin=u, color="b", linestyle="dotted")
plot_vector2d(u, origin=v, color="r", linestyle="dotted")
plot_vector2d(u+v, color="g")
plt.axis([-5, 10, -5, 5])

plt.grid('on')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20555936856554563, 'fraction_numerical': 0.04770075497597804, 'mean_word_length': 5.858823529411764, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, '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': '396609', 'license': 'MIT', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1239, 'n_words': 224, 'path': 'Day1/Day1.ipynb', 'repo_name': 'machinelearning147/100DaysOfMLCode', 'size': '2914'}