I need to create a function that projects vector b onto vector a

I need to create a function that projects vector b onto vector a. I know that all elements of b is 1, and that it has the same dimensions as a. My function needs to work for all dimensions. How do i do this??? Especially the part of defining b
So far i have written this
function projection = computeProjection(a)
projection = (dot(a,b)/norm(a))*a;

 채택된 답변

John D'Errico
John D'Errico 2017년 8월 5일
편집: John D'Errico 2017년 8월 5일
All you are missing is that b is a vector of ones, of the same size as a?
b = ones(size(a));
At least, that is all you think you need. In fact, you need to modify the formula slightly, to be:
projection = (dot(a,b)/norm(a)^2)*a;
You needed another factor of norm(a) in there to make it work.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2017년 8월 5일

편집:

2017년 8월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by