Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

% Clean up the MATLAB space clear all; clc; % 1a. % Obtain a sepcific day from the user in the format MMM DD YYYY

% Clean up the MATLAB space clear all; clc;

% 1a. % Obtain a sepcific day from the user in the format MMM DD YYYY month_input = input('Please enter the month as MMM: ','s'); day_input = input('Please enter the day as DD: ','s'); year_input = input('Please enter the year as YYYY: ','s');

%1b. % Validate the user's input for the day if length(day_input)~=2 error('Day input must have two digits!') end;

% Converting the day input from a string to a number day_input_number = str2num(day_input);

% Enforced the day input must be nummeric if isempty(day_input_number) == 1 error(' Day input must be numeric!'); end; % The day must fall between 1 - 31 if day_input_number ~=1:31 error('Day cannot be validated') end; % Enforce the day input must be an integer if mod(day_input_number,1) ~=0 error('Day input must be an integer'); end;

% Validate the user's input for the year if length(year_input)~=4 error('Year input must have four digits!') end;

% Converting the year input from a string to a number year_input_number = str2num(year_input);

% Enforced the year input must be nummeric if isempty(year_input_number) == 1 error(' Year input must be numeric!'); end; % The year must fall between 1900 - 9999 if year_input_number ~= 1900:9999 error('Year cannot be validated') end; % Enforce the year input must be an integer if mod(year_input_number,1) ~=0 error('Year input must be an integer'); end;

% Determine whether the year is a leap year or not

% Set the month number and the maximum number of days in each month switch month_input case 'JAN' max_days = 31; case 'FEB' if (mod(year_input_number,4)==0 && mod(year_input_number,100)~=0) || mod(year_input_number,400)==0 max_days = 29; else max_days = 28; end; case 'MAR' max_days = 31; case 'APR' max_days = 30; case 'MAY' max_days = 31; case 'JUN' max_days = 30; case 'JUL' max_days = 31; case 'AUG' max_days = 31; case 'SEP' max_days = 30; case 'OCT' max_days = 31; case 'NOV' max_days = 30; case 'DEC' max_days = 31; otherwise ('Input month not recognized'); end; % Peform our calendar aware test if max_days < day_input_number error('Your input month does not contain this day!'); end;

%1c. % Convert the month input to a number switch month_input case 'JAN' month_input_number = 1; case 'FEB' month_input_number = 2; case 'MAR' month_input_number = 3; case 'APR' month_input_number = 4; case 'MAY' month_input_number = 5; case'JUN' month_input_number = 6; case 'JUL' month_input_number = 7; case 'AUG' month_input_number = 8; case 'SEP' month_input_number = 9; case 'OCT' month_input_number = 10; case 'NOV' month_input_number = 11; case 'DEC' month_input_number = 12; end; % Calculate the Julian Day Number, J day = day_input_number; % In case the month input is either January or February, a =1 % a = 0 for the other months if (month_input_number == 1) ||(month_input_number == 2) a = 1; else a = 0; end; % Calculate m, y and J m = month_input_number + 12*a - 3; y = year_input_number -a + 4800; J = day + floor((153*m+2)/5) + 365*y + floor(y/4) - floor(y/100) + floor(y/400) - 32045; % Calculate the elaped number of days DealtaJ since January 1, 1990 J0 = 2415021; DeltaJ = J - J0; % Print the results to the command window fprintf('Julian Day Number J %15.0f The elapsed number of days DeltaJ %15.0f ',J,DeltaJ);

%1d. % Calculate the lunar phase % T is the number of days in each lunar revolution T = 29.530588853; L = (sin(pi*(mod(DeltaJ,T)/T)))^2; % Print the result fprintf('The percent illumination of the moon, L %20.9f ',L);

%1e. % Print the required day format to the command window fprintf('%s %s %s; ',month_input,day_input, year_input); Ill = L*100; fprintf('Illumination %5.1f ',Ill); % Determine the phase of the moon if (mod(DeltaJ,T)/T)< 0.5 fprintf('Waxing'); else fprintf('Waning '); end;

Can anyone help me with this code? I get bug as inputting any day of Feberuary!

Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

=+ a. What is the per-worker production function?

Answered: 1 week ago