Vectors and Vector Operations
Nerd Cafe
1. What Is a Vector?
A vector is a mathematical quantity that has:
Magnitude (length)
Direction
Example:
Displacement of 5 km North is a vector, but just 5 km is a scalar.
2. Vector Representation
A vector in 2D space is written as:
import numpy as np
v = np.array([3, 4])
print(v)Output:
3. Types of Vectors
Zero vector: [0,0]
Unit vector: Magnitude is 1
Equal vectors: Same magnitude and direction
Opposite vectors: Same magnitude, opposite direction
4. Vector Operations
4.1 Addition & Subtraction
Mathematics:
Python:
Output:
4.2 Scalar Multiplication
Mathematics:
Python:
Output:
4.3 Dot Product
Mathematics:
Result is a scalar.
Python:
Output:
Use to find angle or test orthogonality.
4.4 Cross Product (Only in 3D)
Mathematics:
Python:
Output:
4.5 Magnitude or Norm
Mathematics:
Python:
Output:
4.6 Unit Vector
Mathematics:
Python:
Output:
4.7 Angle Between Vectors
Mathematics:
Python:
Output:
5. Vector Visualization in 2D & 3D
5.1 Plotting a Vector in 2D
Let’s plot a vector from the origin to point (x, y).
Python Code:
plt.quiver() draws an arrow from the origin.
Output:

5.2 Plotting Multiple Vectors in 2D
Output:

5.3 Plotting Vectors in 3D
6. Plot Vector Addition Graphically
Output:

Last updated