Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
2  
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]. –  rm -rf May 21 at 13:45
add comment

1 Answer 1

up vote 5 down vote accepted

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]}

share|improve this answer
    
Thank you very much for your valuable explanation! Now it works like a charm. –  ivokabel May 21 at 14:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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