Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using mat lab ements of o.5. Note: you wall need to use a.fox lg In and construc

ID: 2086428 • Letter: U

Question

using mat lab

ements of o.5. Note: you wall need to use a.fox lg In and construct the y equations, Let n go from 1 to 2. Create a function (vec.m) that will calculate and return the positi magnitude of the position should also calculate and return the unit vector if required. The script that calls the function should use the menu function to ask the user if they want the unit vector to be calculated. The function header is shown below-do not change the function header. vector given two coordinate points (A and B). The function functionvarargoutvec( A,B) Use the following coordinates to test your code: A2,3,41 B.1.4 , 6,9] 3. Modify the function above to allow the user to enter the coordinates of a third point (point C) if they want. If C is provided, the position vector and magnitude of AB will be the unit vector calculated then the unit vectors for AB and BC will both be returned to the main script. Formatted print statements should be used in the script to display the results. returned along with the position vector and magnitude of BC. If the user selects to have Recall: r-A-B lu

Explanation / Answer

function [ r,varargout] = vec(a,b)
r=sqrt(a^2+b^2);
x=atan(abs(b/a));
if (a>0 && b<0)
varargout=-1*x;
elseif (a<0 && b>0)
varargout=pi-x;
elseif (a<0 && b<0)
varargout=x-pi;
else
varargout=x;
end
c=input('If u want to calculate the unit vector then press "1" : ');
if c==1
disp('unit vector is :');
disp('x=');a/r
disp('y=');b/r
end
  


end

This is the required program. save it as 'vec.m' and run by giving arguments which will return the magnitude and position of the given vector. Also it can calculate unit vector if asked.