Chapter 3
Calendars and Clocks
Computations involving time, dates, biorhythms and Easter.
Calendars are interesting mathematical objects. The Gregorian calendar was
ﬁrst proposed in 1582. It has been gradually adopted by various countries and
churches over the four centuries since then. The British Empire, including the
colonies in North America, adopted it in 1752. Turkey did not adopt it until 1923.
The Gregorian calendar is now the most widely used calendar in the world, but by
no means the only one.
In the Gregorian calendar, a year
y
is a
leap year
if and only if
y
is divisible
by 4 and not divisible by 100, or is divisible by 400. In
Matlab
the following
expression must be
true
.
For example, 2000 was a leap year, but 2100 will not be a leap year. This rule
implies that the Gregorian calendar repeats itself every 400 years. In that 400year
period, there are 97 leap years, 4800 months, 20871 weeks, and 146097 days. The
average number of days in a Gregorian calendar year is 365 +
97
400
= 365
.
2425.
The
Matlab
function
clock
returns a sixelement vector
c
with elements
c(1) = year
c(2) = month
c(3) = day
c(4) = hour
c(5) = minute
c(6) = seconds
Copyright c
±
2009 Cleve Moler
Matlab
R
±
is a registered trademark of The MathWorks, Inc.
TM
August 8, 2009
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
Chapter 3. Calendars and Clocks
The ﬁrst ﬁve elements are integers, while the sixth element has a fractional part that
is accurate to milliseconds. The best way to print a
clock
vector is to use
fprintf
or
sprintf
with a speciﬁed
format string
that has both integer and ﬂoating point
ﬁelds.
f = ’%6d %6d %6d %6d %6d %9.3f\n’
I am writting this on May 22, 2007, at about 7:30pm, so
c = clock;
fprintf(f,c);
produces
2007
5
22
19
31
54.015
In other words,
year = 2007
month = 5
day = 22
hour = 19
minute = 31
seconds = 54.015
The
Matlab
functions
datenum
,
datevec
,
datestr
, and
weekday
use
clock
and facts about the Gregorian calendar to facilitate computations involving calendar
dates. Dates are represented by their
serial date number
, which is the number of
days since the theoretical time and day over 20 centuries ago when
clock
would
have been six zeroes. We can’t pin that down to an actual date because diﬀerent
calendars would have been in use at that time.
The function
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '11
 Adams
 Math, Gregorian calendar, Easter Day, datenum, serial date number

Click to edit the document details