- #1
OneObstacle
- 6
- 0
Homework Statement
City Latitude(degrees) Longitude(degrees)
LOS ANGELES 35.20 N 118.03 W
CHICAGO 41.82 N 87.62 W
CORVALLIS 44.53 N 123.30 W
MONTREAL 45.50 N 73.58 W
LONDON 51.51 N 0.12 E
BEIJING 40.08 N 116.33 W
RIO DE JANEIRO 22.83 S 43.33 W
MELBOURNE 35.87 S 145.14 E
VLADIVOSTOK 43.10 N 131.78 E
JOHANNESBURG 26.10 S 27.95 E
PUNTA ARENA 53.15 S 70.92 W
SCAMMON BAY 61.83 N 165.57 W
Write a complete MATLAB program that does the following:
a) Print the data as shown. The directions N/S or E/W should be stored as character variables and used to calculate the polar and azimuthal angles α and β respectively.
b) Find the largest surface separation in miles and print the result to 2 decimal places. Also print the corresponding names of the two cities. Your algorithm should be efficient!
Homework Equations
α= 90 - lat (if N)
=90 + lat (if S)
β=long (if W)
= 360-long (if E)
The Attempt at a Solution
clear
clc
fprintf('City Latitude(degrees) Longitude(degrees)\n')
C = char('LOS ANGELES','CHICAGO','CORVALLIS','MONTREAL','LONDON','BEIJING','RIO DE JANEIRO','MELBOURNE','VLADIVOSTOK','JOHANNESBURG','PUNTA ARENA','SCAMMON BAY');
LATDIR = ['N','S','E','W'];
Lat=char('35.20 N','41.82 N','44.53 N','45.50 N','51.51 N','40.08 N','22.83 S','35.87 S','43.10 N','26.10 S','53.15 S','61.83 N');
Long = char('118.03 W','87.62 W','123.30 W','73.58 W','0.12 E','116.33 W','43.33 W','145.14 E','131.78 E','27.95 E','70.92 W','165.57 W');
[nr nc]=size(Long);
for i=1:nr
fprintf('%s %s %s\n',C(i,:),Lat(i,:),Long(i,
end
%Find alpha
[nr nc]=size(Lat);
As you can see, I got the first part of a done and printed the data. However, I have no idea how to call the data and make it recognize that, say, the latitude of Los Angeles is to the north, and as such should use the first equation. Once I get that, I think I can get the rest. Any help would be much appreciated. Thanks!
EDIT: Part of me suspects I should write the matrices for lat and long differently.