1
$\begingroup$

I have previously asked a question in regards to determining the labels of the dynamic graph that I have created, but by using SetAttributes and HoldForm is unfortunately not doing the trick. Currently this is my code (don't mind the formatting):

FNplot[{f__}, 
  t_, {xmin_, xmax_}, {ymin_, ymax_}] := (functions = {f, {}};
  If[ValueQ[number] == False, number = {};];
  Manipulate[
   Show[Table[
      Plot[functions[[k]], {t, xmin, xmax}], {k, 1, 
       Length[functions]}][[number /. {} -> 
        Length[functions]]]], {{number, {}, ""}, 
    Thread[Range[Length[functions] - 1] -> 
      MapThread[
       Row[{"Function " <> ToString[#2], Spacer[20]}] &, {ColorData[
          97] /@ Range[Length[functions] - 1], 
        Range[Length[functions] - 1]}]], ControlType -> CheckboxBar, 
    BaselinePosition -> Center, Method -> "Active", 
    Appearance -> "Vertical"}, ControlPlacement -> Right])

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

FNplot[{FNdsin[1, 1, 90, 0.2, 8.5, 8, 4, t], Cos[t], Tan[t]}, t, {0, 
  2 Pi}, {-1, 1}]

The last line will produce a graph with slider functionality and checkboxes to plot some functions. I want to replace string Function 1, 2, 3 on the right side with the names of the inputted function by the user (in this case: Function 1 should be FNdsin[1, 1, 90, 0.2, 8.5, 8, 4, t], Function 2 should be Cos[t] and Function 3 should be Tan[t].) However,FNdsin[1, 1, 90, 0.2, 8.5, 8, 4, t] is always evaluated as a piecewise function despite me trying to use HoldForm, but I would rather show the name of the function and not the evaluation of the function in the legend. How can I do this? Thank you.

$\endgroup$
  • $\begingroup$ Sure, I'll edit the code so that it's minimal. Sorry about that. $\endgroup$ – Wilson Aug 31 '16 at 7:03
  • $\begingroup$ The code is pretty minimal now. I removed a lot of code changing the color options and plotting properties, but tried to maintain that Manipulate function with the defined function. $\endgroup$ – Wilson Aug 31 '16 at 7:23
  • 1
    $\begingroup$ Add HoldFirst attribute and then you can labels = Thread[HoldForm[{f}]] $\endgroup$ – Kuba Aug 31 '16 at 13:03
  • $\begingroup$ When setting the HoldFirst attribute, are we defining a new function or are we using f? $\endgroup$ – Wilson Aug 31 '16 at 13:43
  • $\begingroup$ Not quite sure what do you mean. I meant SetAttributes[ FNplot, HoldFirst]. $\endgroup$ – Kuba Aug 31 '16 at 13:45

Your Answer

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

Browse other questions tagged or ask your own question.