The gegraphic coordinate system is used to represent any location on Earth as a
ID: 3664035 • Letter: T
Question
The gegraphic coordinate system is used to represent any location on Earth as a combination of latitude and longitude values. These values are angles that can be written in the decimal degrees (DD) form or degrees, minutes, seconds (DMS) form just like time. For example, 24º is equivalent tp 24º30'0". Write a script that will prompt the user for an angle in DD form and will print in sentence format the same angle in DMS form. The script should error-check for invalid user input. The angle conversion is to be done by calling a separate function in the script.
Explanation / Answer
message = 'Please enter the angle in decimal Degrees DD form ';
dd = input(message)
% now to the conversion
% 1 degree = 60 minutes = 3600 seconds
% for example, 24.52 DD = 24 Degrees 31 minutes and 12 seconds
% the formula:
% degrees = integer(24.52) = 24 degrees
% minutes = int( (24.52 - degrees) * 60 ) =
% = int (24.52 - 24 ) * 60 )
% = int (0.52 * 60 )
% = int ( 31.2 ) = 31
% hence minutes = 31 minutes
% seconds = (Decimal Degrees - Degrees - minutes / 60 ) * 3600
% = ( 24.52 - 24 - 31 / 60 ) * 3600
% = ( 24.52 - 24 - 0.517 ) * 3600
% = ( 0.52 - 0.517 ) * 3600
% = ( 0.003333 ) * 3600
% = 12 seconds
% hence seconds = 12 seconds
% in summary
% 24.52 decimal degress = 24 degress, 31 minutes, 12 seconds
% now the above can be written in a MATLAB code:
%
%
% define the function
function dd = functionDDToDegMinSec(dd)
message = 'Please enter the angle in decimal Degrees DD form ';
dd = input(message)
% check whether it is numerical value = error checking
while (~checknum(dd))
if ~checknum(dd)
error('Please enter numerical values with or without decimal points');
end; % end of if
dd = input(message)
end % end of while
degrees = int(dd)
minutes = int(dd - degrees)
seconds = ( dd - degrees - minutes / 60 ) * 3600
print degrees
print minutes
print seconds
print dd
end % end function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.