0
$\begingroup$

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]

enter image description here

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.

$\endgroup$

1 Answer 1

2
$\begingroup$
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]

enter image description here

$\endgroup$
2
  • $\begingroup$ thanks, I didn't know about NumericQ. Is there a way to specify where Plot will sample the function? $\endgroup$ Jan 23 at 14:45
  • $\begingroup$ 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. $\endgroup$
    – Bob Hanlon
    Jan 23 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.