To project vector w onto vector b, we may use the following formula:
proj_b(w) = (dot(w,b)/dot(b,b)) * b,
where dot denotes the dot product of two vectors.
In MATLAB code, this can be done as follows:
main.m63 chars5 lines
Here, w and b are the input vectors, and proj_b_w is the projected vector of w onto b.
gistlibby LogSnag