# Sunrise, Sunset and the Sine Wave.

**URL:** <https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440>\
**Category:** Factual Questions\
**Created:** [January 22, 2014, 10:23am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440 "2014-01-22T10:23:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_B](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/jim_b/32/4338_2.png) [@Jim\_B](https://boards.straightdope.com/u/Jim_B)\
**Post date:** [January 22, 2014, 10:23am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/1 "2014-01-22T10:23:13Z")

</div>

About ten years ago, or thereabouts, I was interested in using the Sine wave to calculate certain natural phenomenon. I had trigonometry in high school. And I am fascinated by anything to do with science in general.

Anyways, I used it first to calculate the average highs and lows of temperature for where I live. For some reason, this follows are fairly regular Sine wave. And so I was successful doing this.

The only thing I could never figure out was the daily sunrise and sunset times for where I lived. I tried to find the equation for this, using the times given in an almanac I had. But I was unable to find the equation. I still don’t know what it is. I just know it is not a regular Sine wave.

So what is the equation for sunrise and sunset? I really would like to know:).

---

<div class="post-metadata">

**Author:** ![Keeve](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Keeve](https://boards.straightdope.com/u/Keeve)\
**Post date:** [January 22, 2014, 10:26am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/2 "2014-01-22T10:26:47Z")

</div>

[https://en.wikipedia.org/wiki/Equation\_of\_time](https://en.wikipedia.org/wiki/Equation_of_time)

---

<div class="post-metadata">

**Author:** ![bob\_2](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bob_2/32/3341_2.png) [@bob\_2](https://boards.straightdope.com/u/bob_2)\
**Post date:** [January 22, 2014, 10:27am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/3 "2014-01-22T10:27:12Z")

</div>

I am no scientist but, curious about your question I searched for an answer and found several, including this:

> [@](#):
>
> The sunrise equation as follows can be used to derive the time of sunrise and sunset for any solar declination and latitude in terms of local solar time when sunrise and sunset actually occur:
> 
> cos(ωo) = -tan(φ)×tan(δ)
> 
> where ωo is the hour angle in degrees at either sunrise (when negative value is taken) or sunset (when positive value is taken) in degree (°); φ is the latitude of the Earth in degree; δ is the sun declination in degrees.
> 
> The Earth rotates at the angular speed of 15°/hour and, therefore, ωo/15° gives the time of sunrise as the number of hours before the local noon, or the time of sunset as the number of hours after the local noon. Here the term local noon indicates the local time when the sun is exactly to the south or north or exactly overhead.
> 
> Read more: [http://www.physicsforums.com](http://www.physicsforums.com)

---

<div class="post-metadata">

**Author:** ![MikeS](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@MikeS](https://boards.straightdope.com/u/MikeS)\
**Post date:** [January 22, 2014, 1:26pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/4 "2014-01-22T13:26:30Z")

</div>

The equation **bob++** wrote above is basically correct. The part of it that varies over the course of the year is δ, the declination of the Sun. [Various approximate expressions exist for this;](http://en.wikipedia.org/wiki/Position_of_the_Sun#Declination_of_the_Sun_as_seen_from_Earth) if we use the simplest one, we find that the day length at a given latitude is of the form

(day length) = cos[sup]-1[/sup](A \* tan(B_cos(C_t)))

where A, B, and C are constants depending on your latitude and various astronomical constants. This function oscillates, of course, but as you discovered it’s not a simple sinusoid.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 22, 2014, 3:39pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/5 "2014-01-22T15:39:06Z")

</div>

For that matter, most of the other phenomena you looked at aren’t simple sinusoids, either, though they can be approximated that way. If you find the best-fit sine wave, you’ll get something pretty close, but with some error. Now subtract out your best fit so all you have left is that error, and you’ll find that you’ll be able to approximate that with another sine wave, but with twice the frequency of the original one. Subtract that out too, and you’ll have another one, with three times the frequency, and so on. Keep on doing this, and what you produce is called the Fourier decomposition of your original function.

---

<div class="post-metadata">

**Author:** ![Stranger\_On\_A\_Train](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Stranger\_On\_A\_Train](https://boards.straightdope.com/u/Stranger_On_A_Train)\
**Post date:** [January 22, 2014, 4:30pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/6 "2014-01-22T16:30:25Z")

</div>

> [@Chronos](#):
>
> For that matter, most of the other phenomena you looked at aren’t simple sinusoids, either, though they can be approximated that way.

This is true of steady state phenomena such as the apparent motion of the Sun but transient phenomena require additional factors to account for the rate of change of absolute amplitude. By combining such functions together, any non-random phenomenon can be represented (or at least approximated to a high degree of precision) in the frequency spectrum as a combination of sinusoidal and exponential functions in the manner that **Chronos** describes (i.e. using the Fourier transform). The really interesting thing is that if you know the characteristics of the function, it can be filtered (subtracted out) of a more complex signal, which is exactly how modern cellular telephony is able to transmit a large number of signals simultaneously in the same frequency band without interference. (Technically there is some amount of signal that is lost, but with modern filtering and anti-aliasing algorithms the losses are small and within the tolerance of reproducing a reasonably accurate audio signal.)

The other interesting thing about this is that it also explains why the discrete phenomena seen at the level of fundamental particles (as described by quantum mechanics) seems continuous at the scale of everyday experience. All fundamental particles are described as “waves of probability” in terms of position and momentum, so when you combine a large number of particles together they behave as a continuum except in very restricted circumstances where they are all coherent (in phase such that minima and maxima all occur simultaneously) as in a [laser](http://hyperphysics.phy-astr.gsu.edu/hbase/optmod/qualig.html) or Einstein-Bose condensate. Even supposed truly random distributions are fundamentally a composition of just a large number of discrete modes (different frequencies) that are sufficiently broadly distributed that you can’t discern the overall distribution. So, fundamentally, all phenomena can be described in terms of waves.

For the o.p., the reason the variation of high and low temperatures can be approximated as a sinusoidal periodic function is that the motion of the Earth in its orbit (which determines the length of the year) and variation of the axial tilt with respect to the Sun both have the same period, i.e. ~365 days. However, as we’re all aware, the actual period is ~365.25 days, necessitating the addition of an intercalary day every four years (with a few other adjustments). If not for this adjustment in the Gregorian calendar, you would see a very slight difference in the frequency of the year versus the temperature cycle which would manifest over a period of centuries, with winter swapping for summer about every 183 years. It is also by this means that variations in the climate over eons can be observed irrespective of local minima and maxima despite sparse data via fitting the data that we do have (or can estimate) to an expected periodic function and optimizing the parameters for best fit.

Stranger

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 22, 2014, 5:21pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/7 "2014-01-22T17:21:06Z")

</div>

> [@](#):
>
> For the o.p., the reason the variation of high and low temperatures can be approximated as a sinusoidal periodic function is that the motion of the Earth in its orbit (which determines the length of the year) and variation of the axial tilt with respect to the Sun both have the same period, i.e. ~365 days. However, as we’re all aware, the actual period is ~365.25 days, necessitating the addition of an intercalary day every four years (with a few other adjustments). If not for this adjustment in the Gregorian calendar, you would see a very slight difference in the frequency of the year versus the temperature cycle which would manifest over a period of centuries, with winter swapping for summer about every 183 years. It is also by this means that variations in the climate over eons can be observed irrespective of local minima and maxima despite sparse data via fitting the data that we do have (or can estimate) to an expected periodic function and optimizing the parameters for best fit.

This depends on how one defines a year. I’m aware of at least seven different definitions. Based on your figure of 183 years, it looks like you’re defining “year” as “exactly 365 days”, but if one instead uses the tropical year, it’ll stay exactly in synch with the temperature cycle, and if one uses the sidereal or apsodal year, it’ll drift relative to the temperature cycle only very slowly, since those are very close to the tropical year.

---

<div class="post-metadata">

**Author:** ![Learjeff](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Learjeff](https://boards.straightdope.com/u/Learjeff)\
**Post date:** [January 22, 2014, 10:20pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/8 "2014-01-22T22:20:57Z")

</div>

> [@Chronos](#):
>
> For that matter, most of the other phenomena you looked at aren’t simple sinusoids, either, though they can be approximated that way. If you find the best-fit sine wave, you’ll get something pretty close, but with some error. Now subtract out your best fit so all you have left is that error, and you’ll find that you’ll be able to approximate that with another sine wave, but with twice the frequency of the original one. Subtract that out too, and you’ll have another one, with three times the frequency, and so on. Keep on doing this, and what you produce is called the Fourier decomposition of your original function.

Thank you Mr. Fourier!

This fact (that any periodic function can be expressed as a series of harmonics) is one of the things that kept Aristotle’s concept of epicycles (to describe the motion of heavenly objects) alive as long as it did.

Chronos’s method essentially converts a function expressed in the time domain (x,y pairs where x is time) into one expressed in the “frequency domain”. Google “Fourier Analysis” for lots more fun!

---

<div class="post-metadata">

**Author:** ![njtt](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@njtt](https://boards.straightdope.com/u/njtt)\
**Post date:** [January 23, 2014, 1:06am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/9 "2014-01-23T01:06:05Z")

</div>

> [@Learjeff](#):
>
> This fact (that any periodic function can be expressed as a series of harmonics) is one of the things that kept Aristotle’s concept of epicycles (to describe the motion of heavenly objects) alive as long as it did.

You mean Ptolemy. (And _epicycles_ were _not_ sufficient for him to account for the observed planetary motions. He also needed to use _eccentrics_ and _equants_.)

---

<div class="post-metadata">

**Author:** ![ZenBeam](https://avatars.discourse-cdn.com/v4/letter/z/3ab097/32.png) [@ZenBeam](https://boards.straightdope.com/u/ZenBeam)\
**Post date:** [January 23, 2014, 2:59am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/10 "2014-01-23T02:59:59Z")

</div>

Can’t you just use epicycles within epicycles? And epicycles within those? I always assumed if you had enough levels of epicycles, you could get whatever accuracy you needed.

---

<div class="post-metadata">

**Author:** ![njtt](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@njtt](https://boards.straightdope.com/u/njtt)\
**Post date:** [January 23, 2014, 4:39am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/11 "2014-01-23T04:39:40Z")

</div>

> [@ZenBeam](#):
>
> Can’t you just use epicycles within epicycles? And epicycles within those? I always assumed if you had enough levels of epicycles, you could get whatever accuracy you needed.

I do not know if that would be possible in principle, but it is not how it was actually done.

Actually, I kind of doubt that it can be done with just epicycles because Ptolemy’s system also used eccentric points and [equants](https://en.wikipedia.org/wiki/Equant), and everybody hated equants. They were considered extremely inelegant, mathematically, but you needed them to get the theory to fit the data. If they could have got by just with more epicycles, I think they would have. Copernicus essentially invented heliocentrism simply because it enabled him to do without equants. (His system still made free use of eccentric points and epicycles - in numbers comparable to those in Ptolemy’s system - and even then he had to invent a special mechanism to account for the path of Mercury.)

---

<div class="post-metadata">

**Author:** ![Learjeff](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Learjeff](https://boards.straightdope.com/u/Learjeff)\
**Post date:** [January 23, 2014, 4:08pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/12 "2014-01-23T16:08:36Z")

</div>

> [@njtt](#):
>
> You mean Ptolemy. (And _epicycles_ were _not_ sufficient for him to account for the observed planetary motions. He also needed to use _eccentrics_ and _equants_.)

First, thanks for mentioning these terms, which were new to me. Ignorance fought!

Aristotle wrote about the celestial spheres. I don’t know whether he originated that. Later, Hipparchus proposed epicycles; someone in between invented eccentrics. Ptolemy proposed equants.

According to [this](http://csep10.phys.utk.edu/astr161/lect/retrograde/aristotle.html), Ptolemy also proposed epicycles on epicycles.

[More on equants and epicycles](http://mathpages.com/home/kmath639/kmath639.htm), nicely presented so that both the dilettante (like me) and the math geek can follow. It doesn’t mention epi-epi-cycles.

In theory, any periodic function can be exactly modeled using a harmonic series, but it might need to be an infinite series, and as pointed out by njtt, it isn’t the solution used by Ptolemy (or at least, the full story). So, I may have been misled by some article that claimed that part of the success of epicycles was this equivalence. In any case, it’s not the full story.

---

<div class="post-metadata">

**Author:** ![Learjeff](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Learjeff](https://boards.straightdope.com/u/Learjeff)\
**Post date:** [January 23, 2014, 4:34pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/13 "2014-01-23T16:34:04Z")

</div>

> [@Learjeff](#):
>
> In theory, any periodic function can be exactly modeled using a harmonic series.

We’d better let a math geek verify this. I know where & when I learned it, but can’t find a good cite, and I’d think that if it were this simple it’d be stated in the Wikipedia article on Fourier series, and if it is, it’s stated in terms I don’t understand well enough to recognize.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 23, 2014, 4:37pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/14 "2014-01-23T16:37:12Z")

</div>

There are all sorts of decompositions of functions that are possible. As a real-world example, some of my colleagues discovered (to their annoyance) that any gravitational wave signal we might ever detect could be interpreted as being due to an appropriate collection of white dwarf binaries (which we know exist and are abundant). This means that determining that we’ve ever found anything other than a white dwarf binary via gravitational waves requires some clever heuristics to decide which is simpler, the collection of binaries or the proposed other object.

And while the full-blown Copernican model (able to exactly match all motions to within the limits of observational precision) was about as complicated as the full-blown Ptolemaic model, its real virtue was that even in its simplest form it could explain all of the qualitative observations, with no complication whatsoever: The existence of retrograde motion for some of the planets; some of the planets always staying near the Sun in the sky; the two sets of planets being disjoint; planets being brightest during retrograde motion; planets going through retrograde motion exactly when they were in opposition to the Sun. All of these are explained even in a perfect-circles, uniform-speed version of Copernicus’ model, but required at least epicycles in the Ptolemaic model (and some features, like retrograde being at opposition, aren’t explained at all by any version of the Ptolemaic model, except in an ad-hoc manner).

---

<div class="post-metadata">

**Author:** ![Keeve](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Keeve](https://boards.straightdope.com/u/Keeve)\
**Post date:** [January 23, 2014, 4:48pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/15 "2014-01-23T16:48:38Z")

</div>

What I’d really **love** is a formula, where all I need to do is plug in a date, a latitude, and a longitude, and it will spit back the sunrise and sunset. I know there are plenty of programs and websites that can do that, but to me, they are black boxes that I cannot adapt for my own purposes.

Could someone create an Excel sheet along the following lines: I enter a date in column A. I enter a latitude in column B. I enter a longitude in column C. Columns D through X are full of ridiculously detailed formulas which build upon each other, containing all sorts of trig functions and arcane constants. Finally, column Y has sunrise and column Z has sunset.

I could probably build such a thing from the formulas in the Wiki article that I cited above, but if I made even a tiny mistake it’d be impossible for me to debug, and that’s why I hope someone else might have already done it.

---

<div class="post-metadata">

**Author:** ![Stranger\_On\_A\_Train](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Stranger\_On\_A\_Train](https://boards.straightdope.com/u/Stranger_On_A_Train)\
**Post date:** [January 24, 2014, 7:08pm UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/16 "2014-01-24T19:08:51Z")

</div>

> [@Keeve](#):
>
> What I’d really **love** is a formula, where all I need to do is plug in a date, a latitude, and a longitude, and it will spit back the sunrise and sunset. I know there are plenty of programs and websites that can do that, but to me, they are black boxes that I cannot adapt for my own purposes.
> 
> Could someone create an Excel sheet along the following lines: I enter a date in column A. I enter a latitude in column B. I enter a longitude in column C. Columns D through X are full of ridiculously detailed formulas which build upon each other, containing all sorts of trig functions and arcane constants. Finally, column Y has sunrise and column Z has sunset.

[Here](http://williams.best.vwh.net/sunrise_sunset_algorithm.htm) is a algorithm from the US Naval Observatory which calculates sunrise and sunset to a reasonable degreee of precision. From the NOAA Earth System Research Lab you can download [this spreadsheet](http://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html) to calculate sunrise and sunset, although I personally would neither use nor trust Excel to perform this calculation due to the “ridiculously detailed formulas” and inherent errors in Excel. I have a more complex application written in C and Python to cummulative caluculate solar incidence over a defined interval for a given set of climate conditions (or alternatively, regression from empirical data) but that is vastly more complex.

Stranger

---

<div class="post-metadata">

**Author:** ![TonySinclair](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@TonySinclair](https://boards.straightdope.com/u/TonySinclair)\
**Post date:** [February 2, 2014, 5:28am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/17 "2014-02-02T05:28:14Z")

</div>

> [@Stranger\_On\_A\_Train](#):
>
> [Here](http://williams.best.vwh.net/sunrise_sunset_algorithm.htm) is a algorithm from the US Naval Observatory which calculates sunrise and sunset to a reasonable degreee of precision. From the NOAA Earth System Research Lab you can download [this spreadsheet](http://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html) to calculate sunrise and sunset, although I personally would neither use nor trust Excel to perform this calculation due to the “ridiculously detailed formulas” and inherent errors in Excel. I have a more complex application written in C and Python to cummulative caluculate solar incidence over a defined interval for a given set of climate conditions (or alternatively, regression from empirical data) but that is vastly more complex.
> 
> Stranger

Thanks for the links. The spreadsheets work fine for me; within a few seconds of the Naval Observatory times, and that’s using Gnumeric, a freeware spreadsheet that I’m surprised even had compatible function names.

---

<div class="post-metadata">

**Author:** ![Keeve](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Keeve](https://boards.straightdope.com/u/Keeve)\
**Post date:** [February 3, 2014, 10:52am UTC](https://boards.straightdope.com/t/sunrise-sunset-and-the-sine-wave/679440/18 "2014-02-03T10:52:12Z")

</div>

> [@Stranger\_On\_A\_Train](#):
>
> [Here](http://williams.best.vwh.net/sunrise_sunset_algorithm.htm) is a algorithm from the US Naval Observatory which calculates sunrise and sunset to a reasonable degreee of precision. From the NOAA Earth System Research Lab you can download [this spreadsheet](http://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html) to calculate sunrise and sunset, although I personally would neither use nor trust Excel to perform this calculation due to the “ridiculously detailed formulas” and inherent errors in Excel. I have a more complex application written in C and Python to cummulative caluculate solar incidence over a defined interval for a given set of climate conditions (or alternatively, regression from empirical data) but that is vastly more complex.
> 
> Stranger

Looks good! Thanks! I don’t know why I didn’t see this when you posted it, but I thank both you for posting it, and **TonySinclair** for the bump!
