1
$\begingroup$

I'm trying to do something like the following: (minimal example, f2 unbound)

case = 2;
f = Switch[case, 1, f1, 2, f2]
Plot[{f2^2}, {f, 0, 10}]

but the plot comes out blank. The second line outputs f2 so it does recognize that f=f2. Any recommendations?

$\endgroup$
3
  • 1
    $\begingroup$ What exactly are you trying to do? Something along the lines of f1 = Sin[x]; f2 = x^2; case = 2; f = Switch[case, 1, f1, 2, f2]; Plot[{f^2}, {x, 0, 10}]? If so, you should check your variables and assignments. f is (presumably) a function, but you'd want Plot to iterate over a variable in that function (x in my example), not over f. $\endgroup$ – Graumagier Nov 1 '15 at 9:42
  • 2
    $\begingroup$ Plot has the HoldAll attribute, so the second argument will not be evaluated (or any of the arguments for that matter). Try Plot[{f2^2}, Evaluate@{f, 0, 10}]. $\endgroup$ – sebhofer Nov 1 '15 at 10:10
  • $\begingroup$ @sebhofer your Evaluate@ trick worked perfectly and is simple, thanks! $\endgroup$ – Hanmyo Nov 4 '15 at 8:03