1
$\begingroup$

I am trying to create a package for other Mathematica programmers to use, but in doing so, I came across an interesting MMA problem which I cannot seem to figure out.

The following code in .nb file works perfectly fine:

FNplot[f_, {xmin_, xmax_, {xname_String, xunit_String}}, {ymin_, ymax_, 
    {yname_String, yunit_String}}] := (
  If[ValueQ[yInt] == False, yInt = {ymin, ymax};];
  If[ValueQ[xInt] == False, xInt = {xmin, xmax};];
  opt = {PlotStyle -> Orange, AxesLabel -> {xunit, yunit}, 
    ImageSize -> 400, Exclusions -> False}; 
Manipulate[
  Plot[f, {t, xmin, xmax}, PlotRange -> 
    If[ValueQ[xInt] == False || ValueQ[yInt] == False, 
      {{xmin, xmax}, {ymin, ymax}}, {xInt, yInt}], Evaluate[opt]],
  {{yInt, {ymin, ymax}, Row[{Spacer[20], Column[StringSplit[yname],
    Center]}]}, ymin, ymax, ControlType -> IntervalSlider, 
    Appearance -> {"Labeled", "Vertical"}, Method -> "Stop",
    MinIntervalSize -> 0.001, ImageSize -> {25, 300}},
  {{xInt, {xmin, xmax}, Row[{Spacer[125], xname}]}, xmin, xmax, 
    ControlType -> IntervalSlider, Appearance -> "Labeled",
    Method -> "Stop", MinIntervalSize -> 0.001, ImageSize -> {300, 25}},
  ControlPlacement -> {Left, Bottom}, LocalizeVariables -> False])

FNdsin[f_, vp_, \[Phi]_, d_, swt_, ct_, nct_, t_] := (s2[n_, T_] := 
    vp*Sin[2*Pi*f*(T - d - (n - 1)*ct) + Pi/180*\[Phi]];
  s[n_, T_] := {s2[n, T], d + (n - 1)*ct < T < d + (n - 1)*ct + swt};
  Piecewise[Table[s[k, t], {k, 1, nct}]])

f = 1; vp = 1; \[Phi] = 90; d = 0.2; swt = 8; ct = 8.5; nct = 4;
FNplot[FNdsin[f, vp, \[Phi], d, swt, ct, nct, t], {0, 32, 
  {"Time Interval", "\[Mu]s"}}, {-1, 1, {"Voltage Interval", "V"}}]

However, when I try to put these functions in a .wl file, evaluating the same codes returns an empty plot with the sliders functioning properly. I have included a BeginPackage[], Begin["Private"] (with tilde symbol after Private), End[], and EndPackage[].

How can I fix this and why does this happen? I would greatly appreciate the help!

$\endgroup$
2
  • 5
    $\begingroup$ I think it is the same problem as here: Derivative in my package return 0 You have Plot with MyPackage`Private`t and then user enters Global`t. p.s. double `` escapes single ` from e.g. Global` . $\endgroup$
    – Kuba
    Aug 26, 2016 at 21:12
  • $\begingroup$ Hello @Kuba, thank you so much for your response. Your response to the problem linked also helped me figure out my mistake. Thank you and my apologies for asking a duplicate question. $\endgroup$
    – Wilson
    Aug 27, 2016 at 22:43

0

Browse other questions tagged or ask your own question.