3. To find a unit vector in the direction of the line that connects two points,
ID: 3599995 • Letter: 3
Question
3. To find a unit vector in the direction of the line that connects two points, you must find the vector between the two points and divide each element of that vector by the magnitude of the vector. For example, to find the unit vector in the direction of the line that connects the points (1, 2) and (4, 6), we first find the vector that connects the two points. This can be done by subtracting the coordinates of one point from the other. So the vector that connects (1, 2) and (4, 6) is (4-1,6-2) (3, 4). The magnitude of this vector can be found by using the Pythagorean theorem. |l(3,4)l 3 + 42 5. So the unit vector in the direction of (3,4) is (3/5,4/5)(0.6, 0.8). Write a function called unitVec that determines a unit vector in the direction of the line that connects two points (A and B) in space. The function should take as input two vectors, each with the coordinates of a point in space. The output should be a vector with the components of the unit vector in the direction from A to B. If points A and B have two coordinates each (i.e, they lie in the x y plane), the output vector should have two elements. If points A and B have three coordinates each (i.e., they lie in general space), the output vector should have three elements.Explanation / Answer
function [X] = unitVec(A,B)
C=B-A;
dimension=size(A,2);
sum=0;
for i=1:dimension
sum=C(i)^2 + sum;
end
MAG=sqrt(sum);
for i=1:dimension
C(i)=C(i)/MAG;
end
X=C;
X
end
X is the output vector
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.