<jupyter_start><jupyter_text>Linear Algebra for ChE Laboratory 4 - Plotting Vector using NumPy and MatPlotLib In this laboratory we will be discussing the basics of numerical and scientific programming by working with Vectors using NumPy and MatPlotLib.  ObjectivesOnce accomplished, the researchers are anticipated to1.   Describe and represent the vectors accordingly.2.   Execute different operations in vector matrices without any difficulties.3. Plot and visualize vectors through coding in Python programming.  Discussion  NumPy Numerical Python, or most commonly known as NumPy, is a public library in python that is used for mathematical operations such as linear algebra problems like arrays, matrices, and scalars & vectors [1]. Scalar quantities are quantities that only have a magnitude whereas vector quantities are quantities that have a magnitude and a direction [2].  Representing Vectors In the most basic sense, a vector is a single-dimensional array. In Python, a vector is a one-dimensional array of lists [3]. A vector can either be represented in a horizontal form named horizontal vector in which is it an array that occupies one line, or a vertical vector in a vertical form which is shown as a list type. As an example, the vector given below has its own horizontal and vertical form. $$ KAKAMBREAD = 3\hat{x} + 4\hat{y} \\KAKAMBRIDGE = 5\hat{x} + 2\hat{y}\\KAKAMRICE = 5\hat{x} + 7\hat{y} \\PINKTILIZER = -5\hat{x} - 9\hat{y}$$ The matrix of the vector represented in a horizontal form:$$ KAKAMBREAD = \begin{bmatrix} 3 & 4\end{bmatrix} , KAKAMBRIDGE = \begin{bmatrix} 5 & 2\end{bmatrix} , KAKAMRICE = \begin{bmatrix} 5 & 7\end{bmatrix} , PINKTILIZER = \begin{bmatrix} -5 & -9\end{bmatrix} $$ The matrix of the vector represented in a vertical form: $$ KAKAMBREAD = \begin{bmatrix} 3 \\ 4\end{bmatrix} , KAKAMBRIDGE = \begin{bmatrix} 5 \\ 2\end{bmatrix} , KAKAMRICE = \begin{bmatrix} 5 \\ 7\end{bmatrix}, PINKTILIZER = \begin{bmatrix} -5 \\ -9\end{bmatrix}$$<jupyter_code>import numpy as np 
KAKAMBREAD = np.array([3, 4])
KAKAMBRIDGE = np.array([5, 2])
KAKAMRICE = np.array([5, 7])
PINKTILIZER = np.array ([[-5],
                             [-9]])
print('Vector KAKAMBREAD is ', KAKAMBREAD)
print('Vector KAKAMBRIDGE is ', KAKAMBRIDGE)
print('Vector KAKAMRICE is ', KAKAMRICE)
print('Vector PINKTILIZER is \n', PINKTILIZER)<jupyter_output>Vector KAKAMBREAD is  [3 4]
Vector KAKAMBRIDGE is  [5 2]
Vector KAKAMRICE is  [5 7]
Vector PINKTILIZER is 
 [[-5]
 [-9]]<jupyter_text>Describing vectors in NumPy Describing vectors through the use of NumPy functions is a way of determining a vector's shape, size, and dimensions. A vector is typically a one-dimensional array [3].<jupyter_code>MALENS = np.array([[12, 5, 14, -9],
                  [1, 0, -1, -0]])
MALENS.shape
MALENS.size
MALENS.ndim<jupyter_output><empty_output><jupyter_text>Vector OperationsThere are four (4) basic operations that can be performed using the Python Program and these are:1. Addition2. Subtraction3. Multiplication4. Division  Addition The addition operation on vectors is done by addition two or more compatible matrices in order to obtain the sum of the following. As an example, vectors $KAKAMBREAD$ and $KAKAMBRIDGE$ are added into each other to acquire vector $KIKO$. $$KIKO = 8\hat{x} +6\hat{y} \\ \\or \\ \\ KIKO = \begin{bmatrix} 8 \\ 6\end{bmatrix} $$<jupyter_code>KIKO = np.add(KAKAMBREAD, KAKAMBRIDGE)
KIKO
KIKO = KAKAMBREAD + KAKAMBRIDGE   
KIKO<jupyter_output><empty_output><jupyter_text>Subtraction The subtraction operation is done by subtracting the vectors from each other element-wise wherein the length of the resultant vector would be difference in the operation. An example of this is by subtracting vector $KAKAMBREAD$ minus vector $KAKAMBRIDGE$.<jupyter_code>CHEL = np.subtract(KAKAMBREAD, KAKAMBRIDGE)
CHEL

CHEL = KAKAMBREAD - KAKAMBRIDGE
CHEL<jupyter_output><empty_output><jupyter_text>Multiplication The multiplication operation on vectors is done by multiplying two or more compatible matrices in order to obtain the product of the following. As an example, vectors $KAKAMRICE$ and $PINKTILIZER$ are multiplied into each other to acquire vector $RISA$.<jupyter_code>RISA = np.multiply(KAKAMRICE, PINKTILIZER)
RISA
RISA = KAKAMRICE * PINKTILIZER
RISA<jupyter_output><empty_output><jupyter_text>Division dwsdw<jupyter_code>NERI = np.divide (KAKAMBREAD, KAKAMRICE)
NERI
NERI = KAKAMBREAD/KAKAMRICE
NERI<jupyter_output><empty_output><jupyter_text>Scaling Scaling is also known as the Scalar Multipliplication which multiplies the scalar value or quantity given into all the elements of the vector matrix or matrices [4]. Given below is vector $ANGAT$ is an example: $$ANGAT = 10 \cdot PINKTILIZER$$<jupyter_code>ANGAT = np.multiply(10,PINKTILIZER)
ANGAT
BUHAY = np.multiply(10,(KAKAMRICE, KAKAMBRIDGE))
BUHAY
LAHAT = np.multiply(10,(KAKAMRICE, KAKAMBRIDGE, KAKAMBREAD))
LAHAT<jupyter_output><empty_output><jupyter_text>MatPlotLib Matplotlib, commonly known as matplotlib.pyplot, is a Python plotting library that uses plt as a coding shortcut. It is a  library that aids in the viewing and analysis of data. This will aid in displaying the matrices. Visualizing Data A vector can be plotted and visualized using the MatPlotLib. Visualizing vectors includes origin, data, colors and scale. A plot can considerably show the resultant, scale, magnitude, slope, and angle of the resultant vector while using the Head to Tail Method.<jupyter_code>import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline
SHOT = [-10, -7]
PUNO = [-7, -10]
plt.scatter(SHOT[0], SHOT[1], label='SHOT', c='green')
plt.scatter(PUNO[0], PUNO[1], label='PUNO', c='magenta')
plt.grid()
plt.legend()
plt.show()
AIK = np.array([-7, -10])
DOC = np.array([-10, -7])
JIL = AIK + DOC
Magnitude = np.sqrt(np.sum(JIL**2))
plt.title("Resultant Vector\nMagnitude: {}" .format(Magnitude))
plt.xlim(7, -24)
plt.ylim(7, -24)
plt.quiver(0, 0, AIK[0], AIK[1], angles='xy', scale_units='xy', scale=1, color='green')
plt.quiver(AIK[0], AIK[1], DOC[0], DOC[1], angles='xy', scale_units='xy', scale=1, color='magenta')
plt.quiver(0, 0, JIL[0], JIL[1], angles='xy', scale_units='xy', scale=1, color='purple')
plt.grid()
plt.show()
Slope = JIL[1]/JIL[0]
Angle = (np.arctan(Slope))*(180/np.pi)
print('Resultant: ',JIL)
print('Slope: ',Slope)
print('Angle: ',Angle)
JESS = AIK.shape[0]
plt.xlim(7, -24)
plt.ylim(7, -24)
plt.quiver(0,0, AIK[0], AIK[1], angles='xy', scale_units='xy',scale=1)
plt.quiver(AIK[0],AIK[1], DOC[0], DOC[1], angles='xy', scale_units='xy',scale=1)
plt.quiver(0,0, JIL[0], JIL[1], angles='xy', scale_units='xy',scale=1)
plt.show()
HELLO = np.array([-7, -10])
PAGKAIN = np.array([-10, 7])
BYE = HELLO + PAGKAIN
GUTOM = np.array([17, -17])
YEHEY = HELLO + PAGKAIN + GUTOM
Magnitude = np.sqrt(np.sum(YEHEY**2))
plt.title("Resultant Vector\nMagnitude: {} \n Resultant: {}" .format(Magnitude, YEHEY))
plt.xlim(10, -27)
plt.ylim(10, -27)
plt.quiver(0, 0, HELLO[0], HELLO[1], angles='xy', scale_units='xy', scale=1, color='pink')
plt.quiver(HELLO[0], HELLO[1], PAGKAIN[0], PAGKAIN[1], angles='xy', scale_units='xy', scale=1, color='magenta')
plt.quiver(BYE[0], BYE[1], GUTOM[0], GUTOM[1], angles='xy', scale_units='xy', scale=1, color='purple')
plt.quiver(0, 0, YEHEY[0], YEHEY[1], angles='xy', scale_units='xy', scale=1, color='red')
plt.grid()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1279101245262588, 'fraction_numerical': 0.024363833243096916, 'mean_word_length': 5.3588640275387265, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '288896', 'license': 'Apache-2.0', 'n_tokens_mistral': 2795, 'n_tokens_neox': 2610, 'n_words': 821, 'path': 'Assignment_9.ipynb', 'repo_name': 'thlystrd/LinearAlgebra_2ndsem', 'size': '7388'}