2
$\begingroup$

I want to plot multiple functions with the same settings side-by-side, so I use the pure function construct (for clarity, I only use one function in this example)

Plot[
   #,
   {x, 0, 1}
   ] & /@
{
   Chop[x, 0.5]
}

however, it somehow ignores the Chop function:

enter image description here

If I plot the function directly

Plot[
   Chop[x, 0.5],
   {x, 0, 1}
]

everything works as expected:

enter image description here

I get similar behaviour with Plot3D. Do you see a problem in my code? Does the pure function and Map mechanism (/@) have something to do with it?

PS: I, in fact, want to use Plot3D. That's why I want to draw multiple plots next to each other instead of plotting all functions within one graphics object. I only chose showing the problem using Plot function in order to make the example simpler.

$\endgroup$
  • 2
    $\begingroup$ Check the output of Chop[x, 0.5]... now you can see that the solution is to prevent Chop[...] inside the {...} from being evaluated until it is "inside" Plot. Now try with Unevaluated@Chop[x, 0.5]. $\endgroup$ – rm -rf May 21 '14 at 13:45
5
$\begingroup$

Chop[x, 0.5] evaluates to x because x is symbolic and not a number. Hence your map is equivalent to

Plot[...] & /@ {x}

which is what you see. The solution then is to prevent Chop from evaluating until it is "inside" Plot and this can be done with Unevaluated:

Plot[#, {x, 0, 1}] & /@ {Unevaluated@Chop[x, 0.5]}

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much for your valuable explanation! Now it works like a charm. $\endgroup$ – ivokabel May 21 '14 at 14:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.