# What's going on with Plot and Mesh here?

Here's a relatively simple function, i[t,lat,i0], that plots solar intensity as a function of time, t, given latitude, lat, and a solar constant, i0:

 cosZenith2[dlat_, time_] :=
Module[{rlat, hour, dec, ha, cosz, \[Sigma]},
rlat = dlat*\[Pi]/180;
hour = 24 FractionalPart[time];
(* Declination *)
dec = 0.4093*Sin[2 \[Pi] (284 + time)/365];
(* Hour angle *)
ha = (hour - 12) \[Pi]/12;
cosz = Sin[dec] Sin[rlat] + Cos[dec] Cos[rlat] Cos[ha];
\[Sigma] = 40;
If[cosz >= 0,
cosz (1 - Exp[-\[Sigma] cosz])/(1 + Exp[-\[Sigma] cosz]), 0]
]

i[t_?NumberQ, lat_, i0_] := i0 cosZenith2[lat, t]


I first tried using a MeshFunction to insure the function is sampled when the sun is up, at t+0.5, but even when Mesh is set to 1000, or even 10000, Plot somehow still skips over most the function.

Plot[i[t, 42, 2000], {t, 1, 50}, Mesh -> 1000] What's going on here, or have I misunderstood Mesh? PlotPoints->200 does work, but if I want to plot 1 year of data, I must set PlotPoints to at least 1000 to get around the Nyquist sampling issue. It would be more elegant to sample at Int[t]+0.5, then let Plot subdivide the function as needed to resolve the function properly.

Clear["Global*"]

cosZenith2[dlat_, time_] :=
Module[{rlat, hour, dec, ha, cosz, σ}, rlat = dlat*π/180;
hour = 24 FractionalPart[time];
(*Declination*)dec = 0.4093*Sin[2 π (284 + time)/365];
(*Hour angle*)ha = (hour - 12) π/12;
cosz = Sin[dec] Sin[rlat] + Cos[dec] Cos[rlat] Cos[ha];
σ = 40;
If[cosz >= 0, cosz (1 - Exp[-σ cosz])/(1 + Exp[-σ cosz]), 0]]


Use NumericQ rather than NumberQ. Compare

NumberQ /@ {E, Pi, GoldenRatio}

(* {False, False, False} *)

NumericQ /@ {E, Pi, GoldenRatio}

(* {True, True, True} *)

i[t_?NumericQ, lat_, i0_] := i0 cosZenith2[lat, t]


Use the options PlotPoints and MaxRecursion

Plot[i[t, 42, 2000], {t, 1, 50},
PlotPoints -> 130,
MaxRecursion -> 5] • thanks, I didn't know about NumericQ. Is there a way to specify where Plot will sample the function? Jan 23 at 14:45
• I do not know of any way to force sampling at specified locations. Increasing PlotPoints and MaxRecursion` are the documented means of plotting all features. Jan 23 at 16:42