Assuming that a and v are column vectors in MATLAB, we need to compute the projection of a onto v. The projection of a onto v can be computed as:
main.m34 chars2 lines
Here, (a'*v)/(v'*v) computes the scalar projection of a onto v and (v'*v) computes the magnitude of v. Finally, we multiply the scalar projection with v to get the projection of a onto v.
The full MATLAB code would be as follows:
main.m96 chars4 lines
The variable projection will now contain the projection of a onto v.
gistlibby LogSnag