Hi I need some help with this series of questions TIA Write

Hi I need some help with this series of questions. TIA

Write a Matlab TUI script to perform the following actions: A. Compute the x-component of each vector, the y-component of each vector, the resultant of all the vectors, and the associated angle of the resultant. B. Display your results in a tabular format. C. Also, write all the input and output vectors to an \'external text file called LASTNAMEHWSET6PROB2.TXT! For your homework, it is not necessary to print the contents of the file. All you need to do is to include the correct code to \'write to this file\'!

Solution

% Program to add vectors
clear;

m = input(\'How many vectors ? \');
mag(1) = 0;
ang(1) = 0;

for i=1:m;
   mag(i+1) = input(\'Enter magnitude of vector \');
   ang(i+1) = input(\'Enter angle of vector \');
end

n=length(mag);
xcomp = mag .* cos(ang * pi/180);
ycomp = mag .* sin(ang * pi/180);

hold on;
grid;
for i = 1:n;
   xvect = [0 xcomp(i)];
   yvect = [0 ycomp(i)];
   plot(xvect,yvect);
disp (\'X component = \');
disp (xcomp(i));
disp (\'Y component = \');
disp (ycomp(i));

end;  

xplt(1) = 0;
yplt(1) = 0;

for i=2:n;
   xplt(i) = xplt(i-1)+xcomp(i);
   yplt(i) = yplt(i-1)+ycomp(i);
end

hold off;
figure;

plot(xplt,yplt,\'y\');
grid;

xsum = sum(xcomp);
ysum = sum(ycomp);
xres = [0 xsum];
yres = [0 ysum];
hold on;
plot(xres,yres,\'r\');

res = sqrt(xsum^2 + ysum^2);
disp (\'Resultant magnitude = \');
disp (res);
resang =180* (atan (ysum/xsum))/pi;

if sign(xsum) == -1;
       ansang = 180 + resang;
   elseif sign(ysum)== -1 ;
       ansang = 360 + resang;
   else
       ansang = resang;
end;      
  
disp (\'Resultant angle = \');
disp (ansang);
hold off;

In our case (After entering values in matlab)

we obtained the following. Please find it below. This is matlab solution.

>> % Program to add vectors
clear;

m = input(\'How many vectors ? \');
mag(1) = 0;
ang(1) = 0;

for i=1:m;
   mag(i+1) = input(\'Enter magnitude of vector \');
   ang(i+1) = input(\'Enter angle of vector \');
end

n=length(mag);
xcomp = mag .* cos(ang * pi/180);
ycomp = mag .* sin(ang * pi/180);

hold on;
grid;
for i = 1:n;
   xvect = [0 xcomp(i)];
   yvect = [0 ycomp(i)];
   plot(xvect,yvect);
disp (\'X component = \');
disp (xcomp(i));
disp (\'Y component = \');
disp (ycomp(i));

end;  

xplt(1) = 0;
yplt(1) = 0;

for i=2:n;
   xplt(i) = xplt(i-1)+xcomp(i);
   yplt(i) = yplt(i-1)+ycomp(i);
end

hold off;
figure;

plot(xplt,yplt,\'y\');
grid;

xsum = sum(xcomp);
ysum = sum(ycomp);
xres = [0 xsum];
yres = [0 ysum];
hold on;
plot(xres,yres,\'r\');

res = sqrt(xsum^2 + ysum^2);
disp (\'Resultant magnitude = \');
disp (res);
resang =180* (atan (ysum/xsum))/pi;

if sign(xsum) == -1;
       ansang = 180 + resang;
   elseif sign(ysum)== -1 ;
       ansang = 360 + resang;
   else
       ansang = resang;
end;      
  
disp (\'Resultant angle = \');
disp (ansang);
hold off;
How many vectors ? 3
Enter magnitude of vector 800
Enter angle of vector 36.87
Enter magnitude of vector 424
Enter angle of vector 238.1
Enter magnitude of vector 408
Enter angle of vector 298.08
X component =
0

Y component =
0

X component =
639.9991

Y component =
480.0011

X component =
-224.0579

Y component =
-359.9640

X component =
192.0472

Y component =
-359.9748

Resultant magnitude =
653.6208

Resultant angle =
338.4637

Resultant Angle: 338.46 degrees

Resultant force: 653.62 N

Vector magnitude X component Y component
800 N 639.99 480.00
424 N -224.05 -359.96
408 N 192.04 -359.97
Hi I need some help with this series of questions. TIA Write a Matlab TUI script to perform the following actions: A. Compute the x-component of each vector, th
Hi I need some help with this series of questions. TIA Write a Matlab TUI script to perform the following actions: A. Compute the x-component of each vector, th
Hi I need some help with this series of questions. TIA Write a Matlab TUI script to perform the following actions: A. Compute the x-component of each vector, th
Hi I need some help with this series of questions. TIA Write a Matlab TUI script to perform the following actions: A. Compute the x-component of each vector, th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site