A Conversation for Calculating the Date of Easter

MATLAB code for Easter

Post 1

AlexAshman

Here it is - have fun...

function [] = easter(Year)
% Converted to MATLAB code by AlexAshman, h2g2.com researcher, in 2006
% Given the Year as a four digit number in the range 1700 - 2299
% Calculate Day and Month of Easter Sunday
% Note 1: the algorithm has not been tested outside this range.
% Note 2: the date returned is the Gregorian Calendar date
% (the one we use now), even for dates in the 18th Century.

if Year == 33
disp('Now that would be telling...')
return
end
if Year>2299|Year<1700
disp('Year outside tested range - please enter a number between 1700 and 2299')
return
end

a = mod(Year,19);
b = fix(Year/100);
c = mod(Year,100);
d = fix(b/4);
e = mod(b,4);
f = fix(c/4);
g = mod(c,4);

h = (b + 8);
h = fix(h/25);
i = (b - h + 1);
i = fix(i/3);
j = (19*a + b - d - i + 15);
j = mod(j,30);
k = (32 + 2*e + 2*f - j - g);
k = mod(k,7);
m = (a + 11*j + 22*k);
m = fix(m/451);
n = j + k - 7*m + 114;

Month = fix(n/31);
Day = mod(n,31) + 1;

switch Month
case 3
Mstring = 'March';
case 4
Mstring = 'April';
otherwise
end

s = struct('Easter', Year, 'Will', 'be on the following date' ,'Month', Mstring, 'Day', Day)


Key: Complain about this post

MATLAB code for Easter

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more