About Vector projection
In data science, machine learning and AI, We always deal with vectors in linear algebra.
There are lots of concepts and formulas we have to know about vectors and one of the most important features of vector related to data science is vector projection.
Vector projection is tightly related to dot product of vectors, so let’s first look at what is dot product of vectors.
What is dot product?
Dot product is the sum of the products of the corresponding entries of the two sequence of numbers.
For example, if A is a vector [1,2]^T and B is a vector [3,4]^T, the dot product of A and B is 1*3 + 2*4 = 9.
[1,2]^T means transpose of [1,2], which is used to express column vector.
You may notice that dot product of vectors becomes scalar value. You have to remember that result of dot product of vectors is scalar value!
It’s not limited in two-dimensional vector and the number of vectors can be larger than two.
If A is [a1, a2, … , an], B is [b1, b2, …, bn] and C is [c1, c2, … cn], the dot product of those vectors is a1*b1*c1 + a2*b2*c2 +… + an*bn*cn.
Let’s make a dot product of same two vectors.
[a1, a2] * [a1, a2] = a1*a1 + a2*a2
In this article, * means dot product.
Let’s imagine the vector is in two-dimensional coordinate system. Then squared root of a1*a1 + a2*a2(which is shown in A1) is a length of that vector.(which is shown in A2)
This leads to formula that dot product of same vector same as squared length of that vector.(which is shown in B1)
Got it, then what is it with vector projection?
Assume that you fully understand the dot product of vectors, let’s find out the relationship between dot product and vector projection.
In C1, you may have learned the formula like C2.
Let’s assume that a, b, c are vectors like C3.
Following the definition of subtraction of vectors, c becomes r-s.
Applying C2, we get the formula C4.
As we learned in dot product above, ||r-s||² is same as (r-s)*(r-s).
Therefore we get the following
As we remove the same value, we get the following.
Finally, We get C5 which have to be remembered.
😡, when does vector projection comes out!
sorry for late.. 😅
Now, let’s get learn about vector projection using what we’ve learned!
Let’s first learn about definition of vector projection.
Vector projection of a vector a on vector b, is the orthogonal projection of a onto a straight line parallel to b. In other words, it is a vector parallel to b.
For example, in D1, a1 is a vector projection of a on b.
The length of a1 is calculated by D2.
As in C5, it is same as D3.
As length of a1 is scalar value, D3 is called scalar projection.
To get vector projection, we have to get a vector right?
How can we get a vector from length of the vector?
We can do it by multiplying unit vector to length of the vector, D3.
The Unit vector of r is calculated by D4.
Therefore, vector projections is calculated by multiplying D4 to D3 like D5.
By calculating D5, we actually get the vector projection of a on b, a1 using a and b applying concept of dot product.
Conclusion
We finally did it! We got vector projection using dot product of vectors.
If you had difficulty reading this article, forgive me..
It’s too hard to write math formula in medium..
Anyway, thanks for reading! Hope this article helps you understand vector projection. 😄