I have written a Manipulate function that shows the changing photoperiod (number of hours of daylight per 24-hour day) to which a latitudinal migrant is exposed before, during, and after each of its annual migrations. The user can dial in the two latitudes and the Julian (ordinal) dates for the start and end of each of the two annual migrations. I would now like it to display the total daylight over a year to which the individual is exposed, depending on the combination of these adjustable parameters. In other words, I would like to estimate the area under the dynamically manipulated curve shown below from x = 0 to x = 365. Note that I am referring to the area under the BOLD (black and red) line, not the light gray lines. Of course, I have tried the Integrate function, but it is either WAY too slow (perhaps I am asking for something that is too computationally involved to do quickly) or maybe I am doing something wrong. Here is the Manipulate function without any attempt to calculate the area under the curve:
Manipulate[
P = ArcSin[0.39795*Cos[0.2163108 + 2*ArcTan[0.9671396*Tan[0.0086*(x - 186)]]]];
ASL = (Sin[DL*Pi/180] + Sin[SL*Pi/180]*Sin[P])/(Cos[SL*Pi/180]*Cos[P]);
CASL = Clip[ASL];
ANL = (Sin[DL*Pi/180] + Sin[NL*Pi/180]*Sin[P])/(Cos[NL*Pi/180]*Cos[P]);
CANL = Clip[ANL];
AMNL = (Sin[DL*Pi/180] + Sin[((((NL*x) - (NL*NMB) - (SL*x) + (SL*NMB))/(NME - NMB)) + SL)
*Pi/180]*Sin[(ArcSin[.39795*Cos[.2163108 + 2*ArcTan[.9671396*Tan[.00860 (x - 186)]]]])])
/(Cos[((((NL* x) - (NL*NMB) - (SL*x) + (SL*NMB))/(NME - NMB)) + SL)* Pi/180]*
Cos[(ArcSin[.39795* Cos[.2163108 + 2*ArcTan[.9671396*Tan[.00860 (x - 186)]]]])]);
CAMNL = Clip[AMNL];
AMSL = (Sin[DL*Pi/180] + Sin[((((SL*x) - (SL*SMB) - (NL*x) + (NL*SMB))/(SME - SMB)) + NL)*
Pi/180]*Sin[(ArcSin[.39795* Cos[.2163108 + 2*ArcTan[.9671396*Tan[.00860 (x - 186)]]]])])/
(Cos[((((SL* x) - (SL*SMB) - (NL*x) + (NL*SMB))/(SME - SMB)) + NL)* Pi/180]*Cos[(ArcSin[
.39795* Cos[.2163108 + 2*ArcTan[.9671396*Tan[.00860 (x - 186)]]]])]);
CAMSL = Clip[AMSL];
Show[
Plot[24 - (24/Pi)*ArcCos[CASL], {x, 0, 365}, PlotRange -> {{0, 365}, {0, 24}}, Ticks ->
{{{79, "Mar 20"}, {172, "Jun 21"}, {265, "Sep 22"}, {355, "Dec 21"}}, {0, 2, 4, 6, 8,
10, 12, 14, 16, 18, 20, 22, 24}}, AxesOrigin -> {0, 12}, PlotStyle -> {Black, Thin}],
Plot[24 - (24/Pi)*ArcCos[CANL], {x, 0, 365}, PlotRange -> {{0, 365}, {0, 24}}, PlotStyle
-> {Black, Thin}],
Plot[24 - (24/Pi)*ArcCos[CASL], {x, 0, NMB}, PlotRange -> {{0, 365}, {0, 24}}, PlotStyle
-> {Black}],
Plot[24 - (24/Pi)*ArcCos[CAMNL], {x, NMB, NME}, PlotRange -> {{0, 365},
{0, 24}}, PlotStyle -> {Red}],
Plot[24 - (24/Pi)*ArcCos[CANL], {x, NME, SMB}, PlotRange -> {{0, 365}, {0, 24}},
PlotStyle -> {Black}],
Plot[24 - (24/Pi)*ArcCos[CAMSL], {x, SMB, SME}, PlotRange -> {{0, 365}, {0, 24}},
PlotStyle -> {Red}],
Plot[24 - (24/Pi)*ArcCos[CASL], {x, SME, 365}, PlotRange -> {{0, 365}, {0, 24}},
PlotStyle -> {Black}]],
{{DL, 0.8333, "Daylight Definition:"}, {0 -> "Sun Center at Horizon", 0.26667 ->
"Sun Top at Horizon", 0.8333 -> "Sun Top Apparent at Horizon",
6 -> "Civil Twilight Included", 12 -> "Nautical Twilight Included",
18 -> "Astronomical Twilight Included"}, Appearance -> "Open"},
{{SL, -70, "Early/Late-Year Latitude"}, -90, 90, Appearance -> "Open"},
{{NL, 70, "Mid-Year Latitude"}, -90, 90, Appearance -> "Open"},
{{NMB, 93, "Early-Year Migration Begins"}, 1, NME, Appearance -> "Open"},
{{NME, 136, "Early-Year Migration Ends"}, (Abs[NL - SL]/21) + NMB, 365,
Appearance -> "Open"},
{{SMB, 229, "Late-Year Migration Begins"}, NME + 1, 355, Appearance -> "Open"},
{{SME, 309, "Late-Year Migration Ends"}, (Abs[SL - NL]/21) + SMB, 364,
Appearance -> "Open"}]
Piecewise
so your "complex" function appears as a single function, then useNIntegrate
on that. $\endgroup$