Answer the Question and correct the script to get the right answer and do the pl
ID: 2988859 • Letter: A
Question
Answer the Question and correct the script to get the right answer and do the plot
Two ships, A and B, depart from two different ports. Ship "A" travels towards the NE (i.e., towards the East in an angle, theta, of 30 degree North) at a speed of 14 miles per hour, while Ship "B" travels South at a speed of 7 miles per hour. At 7 AM, the ships are positioned as shown in the schematic. Complete the script "problem0301.m" such as it prepares a table showing the position [x, y] of each ship as a function of time [t, for 0 le t le 5 hours] (use the schematic and equations provided by the instructor) Expand the output table to display the distance between the two ships as a function of time. If the visibility is 8 miles, when [time, HH:MM], and for how long, would people from the two ships be able to see each other? EXTRA-CREDIT Plot the distance between the two ships as a function of time [For full credit] this plot should include: Your Name, CSU ID, and Problem Title. Axes labels, including units A grid submit the plot along with the script and output tablesExplanation / Answer
clc;
clear;
fprintf(' abdalla allogahi, CSU ID 2537574');
fprintf(' Problem 03 - Assignment 01');
D = zeros(1, 6);
for t=0:1:5
theta = 30;%degrees
vA = 14;
sA = 25;
vB = 7;
sB = 12;
xBo = 0;
yBo = sB;
vBx = 0;
vBy = -vB;
How_long = 0;
%calculating position of ship A
xAo = -sA*cosd(theta);
vAx = vA*cosd(theta);
xA = xAo+(vAx * t);
yAo = -sA*sind(theta);
vAy = vA*sind(theta);
yA = yAo + (vAy*t);
%calculating position of ship B
xB = xBo + (vBx * t);
yB = yBo + (vBy*t);
%preparing table
table1 = [t, xA, yA, xB, yB];
%calculating distance b/w ships
d = sqrt(((xA)^2 - (xB)^2) + ((yA)^2 - (yB)^2));
D(t+1)= d
table2 = [t, xA, yA, xB, yB, D];
fprintf('table2 for ship is')
table2
if d <= 8
Time = 7 + t
time_to_see = [Time, 00:00];
How_long = How_long + 1;
end;
end;
fprintf('people shall be able to see each other from')
time_to_see
fprintf('and for time')
How_long
t = 0:1:5
plot(t, D)
title('abdella allogahi, 2537574, problem3');
xlabel('time in hours');
ylabel('distance in miles');
grid on;