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

Prepare the flowchart and MATLAB code for an algorithm that will read time and p

ID: 3815761 • Letter: P

Question

Prepare the flowchart and MATLAB code for an algorithm that will read time and position data (latitude and longitude) for two boats in a race from a file and will determine and output the number of times the boats are within 27 meters of each other. The output will be saved in a data file that will be called boatsclose.txt. This output file will contain the following line “The boats come within 27 meters of each other ____ times.” where the “____” is replaced by the number of times the boats come within 27 meters of each other using fprintf to create this sentence.

Prepare the flowchart and MATLAB code for an algorithm that will read time and position data (latitude and longitude) for two boats in a race from a file and will determine and output the number of times the boats are within 27 meters of each other. The output will be saved in a data file that will be called boatsclose.trt. This output file will contain the following line The boats come within 27 meters of each other times." where the is replaced by the number of times the boats come within 27 meters of each other using fprintf to create this sentence program will call a user-defined function (that you to compute distances from latitude and longitude data. You will use data from the America's Cup race provided to test your program Helpful information for creating the distance function: Use the following equations to turn latitude and longitude into actual distances using the Haversine formula d distance between two points given the latitude and longitude of those points R earth's radius (mean radius 6,371 km) Alat lat2 at Along long2- longi Haversine a sin (Alat/2)+ cos lati) cos (lat2)*sin (Along/2) formula c 2*atan2(va, v(1-a) the results of this equation must be in radians in order to be used in the formula for distance below NOTE: The boat datasets contain latitude and longitude in degrees. The data files have headers that need to be stripped in order to load into MATLAB

Explanation / Answer

function distance = dist_calculator(lat1,lat2,long1,long2)

%% calculate the distance

R=6371;

del_lat=lat2-lat1;

del_long=long2-long1;

a=sind(del_lat/2)+cosd(lat1)*cosd(lat2)*(sind(del_long/2))^2;

c=2*atan2(sqrt(a),sqrt(1-a));

distance=R*c;

end

Output :

>> dist_calculator(10,15,74,84)

ans =

2.8981e+03