Matlab help pls Write a user-defined MATLAB function that determines the unit ve
ID: 3700167 • Letter: M
Question
Matlab help pls
Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B). For the function name and arguments, use n-unitvec(A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corresponding point. The output is a vector with the components of the unit vector in the direction from A to B. Use the 'unitvec function as a sub or nested function for the primary function 'analines function which determines the angle that forms by the intersection of two lines. For the function name and arguments, use th-analines(A,B,C). The input arguments to the function are vectors with the coordinates of the points A, B, and C, as shovwn in the figure. Determine the angle for the following case: A-5 1. 6), B(3.5, -6.5), C(-2.3, 8, 1). Include H1 and help text lines for each function such that user can search for the command and/or synta without opening the file.Explanation / Answer
function n=unitvec(A,B)
vector=[B(1)-A(1);B(2)-A(2);B(3)-A(3)];
mag=sqrt(sum(vector.^2));
n=vector./mag;
end
Explanation:
function th=anglines(A,B,C)
vec1=[A(1)-B(1);A(2)-B(2);A(3)-B(3)];
vec2=[C(1)-B(1);C(2)-B(2);C(3)-B(3)];
mag1=sqrt(sum(vec1.^2));
mag2=sqrt(sum(vec2.^2));
th=acos((vec1'*vec2)/mag1/mag2);
end
Explanation: