Transcribed Text
Part 1: Resultant Vector
Write a MATLAB function Mfile named ResVec to compute the resultant of two vectors.
Each of these vectors is a separate input to the function. They are in polar form, magnitude
and angle, in degrees. The output vector is also in polar form. The output angle must always
be positive, measured from the positive xaxis. The input angles may be negative.
Examples:
>> vec2  [190];
>> vecR  ResVec(vecl,vec2)
vecR 
1.4142 45.0000
>> r1  [5  25];
>> r2  [10 295] ;
>> ResVec (r1, r2)
ans 
14.1987 308.0825
Code Restrictions
You may not use MATLAB built  in functions that convert coordinates between polar and
Cartesian form. You may not use atan2 or atan2d. Use of these functions will result in a
zero for the project.
Input Restrictions:
The function should return a red error message for the following conditions.
Not having both a magnitude and angle in the input arguments
The input angles must be between  360 and 360
Part 2: Resultant Vector plotting
Write a MATLAB script Mfile named ResVecPlot to
a) Plot the example input vectors from Part 1, and their resultants, as shown below.
15

o
is
*
<>

*
,
is

a
.
the
All vectors are drawn from the origin. Notice that each graph axis has been adjusted, and
that there is a legend.
b) Print the resultant vectors to the screen using fprintf, as shown below:
Vector #1 magnitude: 1
Vector 41 direction: 0 degrees
Vector 42 magnitude: 1
Vector 42 direction: 90 degrees
resultant vector magnitude: 1.414
resultant vector direction: 45 degrees
Vector 41 magnitude: 5
Vector 41 direction: 25 degrees
Vector 42 magnitude: 10
Vector 42 direction: 295 degrees
resultant vector magnitude: 14.2
resultant vector direction: 308.08degrees
The script file should call (use) the function ResVec from Part 1 to compute the resultant
vector. No credit will be given if the resultant vector is computed any other way.
These solutions may offer stepbystep problemsolving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skillbuilding and practice.
Unethical use is strictly forbidden.
function Main()
vec1=[1 0];
vec2=[1 90];
vecR1=ResVec(vec1,vec2)
v1=[5 25];
v2=[10 295];
vecR2=ResVec(v1,v2)
%We change in cartesian coordinates
vec1=[1 0]; x1=vec1(1)*cos(vec1(2)*pi/180); y1=vec1(1)*sin(vec1(2)*pi/180);
vec2=[1 90];x2=vec2(1)*cos(vec2(2)*pi/180); y2=vec2(1)*sin(vec2(2)*pi/180);
X1=vecR1(1)*cos(vecR1(2)*pi/180); Y1=vecR1(1)*sin(vecR1(2)*pi/180);
clf
hold on
xlim([1 1.5])
ylim([1 1.5])
set(gca,'ytick',0:.5:5)
set(gca,'xtick',0:.5:5)
plot([0 x1],[0 y1],'r',[0 x2],[0 y2],'b',[0 X1],[0 Y1],'k')
legend('vec1','vec2','vecR1=vec1+vec2')
hold off
v1=[5 25]; x1=v1(1)*cos(v1(2)*pi/180); y1=v1(1)*sin(v1(2)*pi/180);
v2=[10 295];x2=v2(1)*cos(v2(2)*pi/180); y2=vec2(1)*sin(v2(2)*pi/180);
vecR2=ResVec(v1,v2...