In linear algebra, understanding orthogonal and orthonormal vectors is crucial, especially for applications in machine learning. This blog post will simplify these concepts without delving too deeply into complex mathematics.
Orthogonal Vectors
Two vectors are considered orthogonal if their dot product equals zero. But what exactly is the dot product? The dot product (or scalar product) of two n-dimensional vectors, A and B, can be expressed as follows:
A · B = ∑ (from i=1 to n) a_i * b_i
Thus, vectors A and B are orthogonal if:
A · B = 0
Example
Consider two vectors in 3D space:
v1=[1,−2,4]v_1 = [1, -2, 4]v1=[1,−2,4]
v2=[2,5,2]v_2 = [2, 5, 2]v2=[2,5,2]
To check if they are orthogonal, we calculate their dot product:
v_1 · v_2 = [1, -2, 4] · [2, 5, 2] = 1*2 + (-2)*5 + 4*2 = 0
Since the result is zero, the vectors are orthogonal.
Python Code Example
Here's a simple Python program that illustrates orthogonal vectors:
# A python program to illustrate orthogonal vector
# Import numpy module
import numpy
# Taking two vectors
v1 = [[1, -2, 4]]
v2 = [[2, 5, 2]]
# Transpose of v1
transposeOfV1 = numpy.transpose(v1)
# Matrix multiplication of both vectors
result = numpy.dot(v2, transposeOfV1)
print("Result =", result)
# Output
# Result = 0
Unit Vectors
Next, let's discuss unit vectors. A unit vector is derived from a vector by dividing it by its magnitude. For a vector AAA, the unit vector a^\hat{a}a^ is defined as:
\hat{a} = A / |A|
Example
Consider a vector AAA in 2D space:
- A=[3,4]A = [3, 4]A=[3,4]
The magnitude of AAA is calculated as follows:
|A| = √(3² + 4²) = 5
Thus, the unit vector a^\hat{a}a^ is:
\hat{a} = A / |A| = [3/5, 4/5]
Properties of Unit Vectors
Unit vectors define directions in a coordinate system.
Any vector can be expressed as a product of a unit vector and a scalar magnitude.
Orthonormal Vectors
Orthonormal vectors are not only orthogonal but also have unit magnitude. To convert orthogonal vectors into orthonormal vectors, simply divide each vector by its magnitude.
For the vectors we considered earlier:
- For v1=[1,−2,4]v_1 = [1, -2, 4]v1=[1,−2,4]:
v_1' = v_1 / |v_1| = [1, -2, 4] / √(1² + (-2)² + 4²)
- For v2=[2,5,2]v_2 = [2, 5, 2]v2=[2,5,2]:
v_2' = v_2 / |v_2| = [2, 5, 2] / √(2² + 5² + 2²)
By converting these vectors into unit vectors, they remain orthogonal and achieve unit magnitude, hence forming orthonormal vectors.
Note
All orthonormal vectors are inherently orthogonal, as defined by their properties.
For more content, follow me at — https://linktr.ee/shlokkumar2303