2
$\begingroup$

I had an odd issue where my plot wasn't drawn correctly when I called it via Plot[Join[fs,gs], (*..*)]. However, these two versions worked:

funcs = Join[fs,gs]; Plot[funcs, (*..*)]           (*1*)

plot[fs_] := Plot[fs,(*..*)]
plot[Join[fs,gs]]                                  (*2*)

After a bit of playing around and a bit of research, I found out that explicitly Evaluate-ing the Join expression fixes the plot, so

Plot[Evaluate[Join[fs,gs]],(*..*)]                 (*3*)

works the same way as the two other examples. It turns out, Plot has the attribute HoldAll set whereas Set and SetDelayed do not.

Hence I suspect that $(1)$ and $(2)$ evaluate the Join expression before passing it to the plot. But

  1. Is there a reason why Plot holds its arguments?
  2. Does that mean if my expression for the plot gets more intricate, I should always Evaluate just to be sure? The documentation just says

In some cases, it may be more efficient to use Evaluate to evaluate f symbolically before specific numerical values are assigned to x.

$\endgroup$
2
  • 7
    $\begingroup$ I believe it's to allow Plot to localize the independent variable before evaluation so as to avoid any existing definition. $\endgroup$ Commented Feb 5, 2022 at 21:39
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/1731/…. In particular, Mr. Wizard's answer recommends using Evaluated -> True instead of Evaluate[funcs]. $\endgroup$ Commented Feb 6, 2022 at 5:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.