How close to a sine wave is the length of daylight?
How close to a sine wave is the length of daylight?
Get the length of daylight over a 16-year period starting on Jan 1, 2009
In[]:=
years=DateObject[{2009,1,1,0,0,0}]+Quantity[Range[0,16*365.25],"Days"];
In[]:=
daylight=TableQuantityMagnitudeSunset,d-Sunrise,d,"Minutes",{d,years};
In[]:=
data=Transpose[{Range[0,16*365.25],daylight}];
Model it as a sine wave. The parameters are mean, amplitude, period, and phase
In[]:=
model=m+aSin[2Pi(t-f)/p]
Out[]=
m+aSin
2π(-f+t)
p
In[]:=
fit=FindFit[data,model,{{m,12*60},{a,3*60},{f,80},{p,365}},t]
Out[]=
{m733.209,a177.294,f79.5669,p365.249}
In[]:=
modelf=model/.fit
Out[]=
733.209+177.294Sin[0.0172025(-79.5669+t)]
Find the error of the model and plot it
In[]:=
err=daylight-Table[modelf,{t,0,16*365.25}];
In[]:=
ListPlot[err]
Out[]=
In[]:=
ListPlot[Part[err,1;;365]]
Out[]=