Finding azimuthal and polar angles

In summary, this MATLAB program prints a table of cities, their latitude and longitude, and then finds the largest surface separation in miles between two cities. The alpha and beta angles are calculated based on the directions of N/S and E/W. The program also calculates the farthest distance between two cities and prints the result with the corresponding city names.
  • #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.
 
Physics news on Phys.org
  • #2
Okay, rewrote the matrices so that instead of 3, I have 5, two of which are numerical and 3 of which are alpha-numerical. Here is my new code(so far):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');
Lat=[35.20;41.82;44.53;45.50;51.51;40.08;22.83;35.87;43.10;26.10;53.15;61.83];
Latdir=char('N','N','N','N','N','N','S','S','N','S','S','N');
Long=[118.03;87.62;123.30;73.58;0.12;116.33;43.33;145.14;131.78;27.95;70.92;165.57];
Longdir=char('W','W','W','W','W','E','W','E','E','E','W','W');
[nr nc]=size(Long);
for i=1:nr
fprintf('%s %5.2f%s %5.2f%s\n',C(i,:),Lat(i,:),Latdir(i),Long(i,:),Longdir(i))
end
%Find alpha
[nr nc]=size(Lat);
 
  • #3
If anybody could help, I'm up to:


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');
Lat=[35.20,41.82,44.53,45.50,51.51,40.08,22.83,35.87,43.10,26.10,53.15,61.83];
Latdir=['N';'N';'N';'N';'N';'N';'S';'S';'N';'S';'S';'N'];
Long=[118.03,87.62,123.30,73.58,0.12,116.33,43.33,145.14,131.78,27.95,70.92,165.57];
Longdir=['W';'W';'W';'W';'W';'E';'W';'E';'E';'E';'W';'W'];
[nr nc]=size(Long);
for i=1:nc
fprintf('%s %5.2f%s %5.2f%s\n',C(i,:),Lat(i),Latdir(i),Long(i),Longdir(i))
end
%Find alpha and beta
n=length(Latdir);
for i=1:n
if Latdir(i)=='N'
alpha(i)=Lat(i)-90;
else
alpha(i)=Lat(i)+90;
end
if Longdir(i)=='W'
beta(i) = Long(i);
else
beta(i) = 360-Long(i);
end
end
R=3958.9;
n=length(Lat);
s=0;
for i=1:n-1
for j=1:n

x(i)=cosd(alpha(i)).*cosd(alpha(j))+sind(alpha(i)).*sind(alpha(j)).*cosd(beta(j)-beta(i));
d(i)=x(i)*R;
end
if abs(d(i))>s
s=d(i);
end
end
fprintf('The farthest distance is %6.2f between %sand %s\n',s,C(i,:),C(j,:))



I think there is a problem with my "limits" on i and j, the bolded part. Any ideas?
 

1. What is the difference between azimuthal and polar angles?

Azimuthal angle refers to the angle measured in the horizontal plane from a reference direction, often the north direction. Polar angle, on the other hand, refers to the angle measured in the vertical plane from a reference plane, often the equatorial plane.

2. How are azimuthal and polar angles used in scientific research?

Azimuthal and polar angles are commonly used in fields such as astronomy, physics, and geology to describe the position and movement of objects in space. They are also utilized in navigation and mapping, as well as in the study of climate and weather patterns.

3. How do you find the azimuthal and polar angles of an object?

The azimuthal and polar angles of an object can be found by using various instruments such as a compass, sextant, or theodolite. These instruments measure the angles relative to a fixed reference point or direction, and can be used to calculate the precise coordinates of an object.

4. Can azimuthal and polar angles be negative?

Yes, azimuthal and polar angles can be negative. In the case of azimuthal angles, negative values indicate a direction on the opposite side of the reference direction. For polar angles, negative values indicate a position below the reference plane.

5. How do azimuthal and polar angles relate to spherical coordinates?

Azimuthal and polar angles are two of the three coordinates used in spherical coordinates, with the third being the radial distance. These angles are used to locate a point in three-dimensional space, and are particularly useful for representing objects on a sphere, such as celestial bodies.

Back
Top