2
$\begingroup$

I'm struggling with the following code

f[x_] := {Undefined, x};
Plot[ f[x] , {x, 0, 1}]                    
Plot[{f[x][[1]], f[x][[2]]}, {x, 0, 1}]
f[x] == {f[x][[1]], f[x][[2]]}

The first plot produce blank figure and the second plot gives the graph of x as expected. What is puzzling, the last condition evaluates to True.

Can you please explain to me why the first plot gives blank plot while the second does not?

$\endgroup$
4
  • 2
    $\begingroup$ Try Plot[Evaluate@f[x],... $\endgroup$
    – Kuba
    Commented Jan 23, 2016 at 9:09
  • $\begingroup$ @Kuba Thank you, it works. But I can break it with x=1 at the top, then the first plot shows one. $\endgroup$
    – tom
    Commented Jan 23, 2016 at 9:23
  • $\begingroup$ Yep, there is Evaluated->True option, but I haven't used it recently, also it is undocumented. But at least it preserves scoping. $\endgroup$
    – Kuba
    Commented Jan 23, 2016 at 9:35
  • $\begingroup$ closely related: 1731 $\endgroup$
    – Kuba
    Commented Jan 23, 2016 at 9:35

0

Browse other questions tagged or ask your own question.