Matlab help. This script gives the # of occurrences of Easter between 2000 and 2
ID: 2267976 • Letter: M
Question
Matlab help. This script gives the # of occurrences of Easter between 2000 and 2100.
c = zeros(1,31);
for year = 2000:2100
dn=easter(year);
fulldate=datevec(dn);
date=fulldate(3);
c(date) = c(date) + 1;
end
bar(c)
avg = sum(c)/31;
axis([0 32 0 max(c)+1])
line([0 31], [avg avg],'linewidth',4,'color','black');
xlabel('Date');
ylabel('Number of Occurances');
title('Date that Easter Falls in the 21st Century From 2000 to 2100')
This script determines how many times Easter occurs in April and march between 2000 and 2100.
Easter_in_March = 0;
Easter_in_April = 0;
for y = 2000:2100 % 21 st century
g = mod(y,19) + 1;
c = floor(y/100) + 1;
x = floor(3*c/4) - 12;
z = floor((8*c + 5)/25) - 5;
e = mod(11*g + 20 + z -x, 30);
if (e == 25 && g>1 || e==24)
e = e + 1;
end
n = 44 - e;
if n<21
n = n + 30;
end
d = floor(5*y/4) - x - 10;
d = n + 7 - mod(d+n,7);
if d <32
Easter_in_March = Easter_in_March + 1;
else
Easter_in_April = Easter_in_April + 1;
end
end
fprintf('in 21st Century %g times Easter occurs in March', Easter_in_March)
fprintf(' %g times Easter occurs in April', Easter_in_April)
Knowing how many dates Easter can occur in March and April, I need to make a script that will determine how many different dates Easter can not occur in March and April.
Hint: Making a 1 X 31 vector c that holds the possible dates in March can be used to find the dates that don't occur by length(find(c==0))
Explanation / Answer
You have the solution in the above two scripts only.
You can have a vector of size 31 having zeros/ones initially. In the second script whenever you increment the number of times easter occurs in march/april you can use the first script eater function to determine the exact date as in the done fisrt script and then complement that particular index in the vector taken initially. After the loop exits you can use the remaining vector to print all dates where easter cannot occur in March and April in 21st century