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

I need help writing a code in matlab Problem 2 The shortest distance between two

ID: 3788820 • Letter: I

Question


I need help writing a code in matlab Problem 2 The shortest distance between two points on the surface of the globe (great-circle distance) can be calculated by using the haversine formula. If $1 and M1 are the latitude and longitude of point 1 and 42 and N2 are the latitude and longitude of point 2, the great circle distance between the points is given by the equation 2R sin-1(Va) where cos (41) cos(42) sin? a F Sin and 3,959 mi is the Earth radius. Write a user-defined function that determines the distance between two points on the Earth. For the function name and arguments, use dis GreatCirDis(Lat1,Lng1,Lat2,Lng2), where the input arguments Page 1

Explanation / Answer

I have written the matlab code for calculating the distance and read the comments for proper explanation. London to newyork I have calculated and written in code comment.

function dis = GreatCirDis(Lat1,Lng1,Lat2,Lng2)
sin1 = sind(Lat2-Lat1);
sin2 = sind(Lng2-Lng1);

%calculating a
a = sin1*sin1 + cosd(Lat1)*cosd(Lat2)*sin2*sin2;
r = 3959;
%calculating the sin inverse
sininv = (asin(a));
% according to the formula
dis = 2 *r*sininv;

fileID = fopen('GreatCircle.txt','w');
fprintf(fileID,'%f',dis);
end
%for london-new york data
Lat1 = 51.50853;
Lat2 = 40.71427;
Lng1 = -0.12574;
Lng2 = -74.00597;
% London to new york output is 3878.40681580393mi
dis =GreatCirDis(Lat1,Lng1,Lat2,Lng2);