Projecting a vector to another vector
이전 댓글 표시
I would like to project a vector to another vector. You can find more information here:
For example I would like to project vector A to vector B. I have used these tricks but it does not work: Any comment is appreciated.
-----------------------
Solution 1)
A=[-10,10,0];
B=[0,0,1];
C=(dot(A,B)/norm(B)^2)*B
---------------------------------
Solution 2)
A=[-10,10,0];
B=[0,0,1];
CosTheta = dot(A,B)/(norm(A)*norm(B));
ThetaInDegrees = acos(CosTheta)*180/pi;
c=norm(A)*cos(ThetaInDegrees)
-----------------------------
댓글 수: 1
Matt Fig
2011년 3월 2일
You should select a best answer if your question has been answered.
채택된 답변
추가 답변 (9개)
Paulo Silva
2011년 2월 28일
A=[-10,10,0];
B=[0,0,1];
%calculation of the projection of A into B
C=(sum(A.*B)/(norm(B)^2))*B;
%versors of each vector
An=A/norm(A);
Bn=B/norm(B);
Cn=C/norm(C);
%graphic representation
clf
line([0 A(1)],[0 A(2)],[0 A(3)],'LineWidth',10,'Color',[0 0 1])
line([0 B(1)],[0 B(2)],[0 B(3)],'LineWidth',8,'Color',[0 1 0])
line([0 C(1)],[0 C(2)],[0 C(3)],'LineWidth',5,'Color',[1 0 0])
legend('A','B','proj A into B')
xlabel('X')
ylabel('Y')
zlabel('Z')
view(80,10)
댓글 수: 5
Victor
2011년 2월 28일
Paulo Silva
2011년 2월 28일
there's something wrong with the code, please hold on
Matt Fig
2011년 2월 28일
Nice catch Paulo!
Use .*, .^ and ./ when you want to perform element-by-element operations. This makes no difference when one of the operands is scalar. Look at the difference for arrays:
A = [1 2;3 4];
B = [3 4;5 6].';
A*B
A.*B
3*A % No difference
3.*A
Paulo Silva
2011년 2월 28일
Should be working properly now
Victor
2011년 3월 1일
Jan
2011년 3월 1일
What exactly does "but it does not work" mean?
Your solution 1:
A = [-10,10,0];
B = [0,0,1];
C = (dot(A,B)/norm(B)^2)*B
This looks ok. If you get C = [0,0,0], the method works. A and B are orthogonal, such that the projection is zero.
Your solution 2: wrong
CosTheta = dot(A,B)/(norm(A)*norm(B));
ThetaInDegrees = acos(CosTheta)*180/pi;
c=norm(A)*cos(ThetaInDegrees)
Now c is a scalar, but you wanted a vector. Converting Theta in degrees is not correct here: COS works win radians. Use COSD for degerees. Improved:
CosTheta = dot(A,B) / (norm(A)*norm(B));
C = norm(A) * CosTheta * B / norm(B);
And as expected: If you insert CosTheta in the 2nd line, you get your solution 1 again.
댓글 수: 2
Paulo Silva
2011년 3월 1일
I failed somehow to find the function dot and done sum(A.*B) instead :) but the results are the same
Jan
2011년 3월 1일
sum(A.*B) and A*B' are faster then DOT. But for [1 x 3] vectors this does not matter.
Foday Samura
2020년 5월 1일
0 개 추천
Find the length (or norm) of the vector that is the orthogonal projection of the vector a = [ 1 2 4 ] onto b = [6 10 3 ]. Type an answer that is accurate to 3 decimal places. (For example, if your answer is 4+2/3, you should type 4.667).
fatema hasan
2020년 12월 13일
0 개 추천
- Write the complete MATLAB commands to find the unit vector parallel to the projection of #5
fatema hasan
2020년 12월 13일
0 개 추천
- If A= <1,2,3>, B = <4,5,6>, write the complete MATLAB commands to compute the projection of A on B
fatema hasan
2020년 12월 13일
0 개 추천
- Compute the partial derivative of x2y3sin(e2xy) in MATLAB with respect to y
Answer:
Syms x,y,z
f=x^2 + y^3 + sin(x*y);
diff(f,x)
diff(f,y)
fatema hasan
2020년 12월 13일
0 개 추천
- Given two vectors: <1,4,3> and <1,0, -2>
Write the complete MATLAB commands to find the dot product
Brandon O'Neill
2021년 3월 26일
0 개 추천
At a certain time of day the radiant energy from the sun reaches the roof along the direction given by the unit vector
The fraction of the sun’s energy which is falling perpendicularly on the roof is the projection of vector (A) onto the direction perpendicular to the roof – this is the dot product of (A) with the unit vector.
Q1) Use Matlab to calculate the fraction of the sun’s energy which is falling perpendicularly on the roof.
can anyone help with this?
the univ vector is [0.7627;0.5509;0.3390]
the vector A = 1/sqrt(21)[1;2;-4]
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!