I have an expression from which I'm trying to create a plot that I can manipulate. The expression contains Abs, and I only want to have it evaluated for reals. What happens when I manipulate the plot is that it is appears to render even when Abs is taking on a complex value, which is something I want to prevent.

Is there a way to restrict the rendering only when a Real number is produced, and ... I don't know ... show a blank plot otherwise.


example function

e1 = Abs[Sqrt[delta*Cos[theta] - b]]
e1 // Manipulate[Plot[#, {theta, 0, 2 Pi}], {b, 0, 2}, {delta, 0, 2}] &
  • $\begingroup$ Dan, Would you include some code so we know the specific function you are working with? $\endgroup$
    – DavidC
    Apr 9, 2013 at 0:34
  • $\begingroup$ David, I can do that, but the function is fairly hairy... and I don't know how to reduce it to a point where it still illustrates the problem. $\endgroup$
    – Dan G
    Apr 9, 2013 at 1:07
  • $\begingroup$ I updated the question with a simplified function $\endgroup$
    – Dan G
    Apr 9, 2013 at 1:14

1 Answer 1


The problem is that Abs[Sqrt[e]] automatically simplifies to Sqrt[Abs[e]]. Perhaps the easiest way is to define a real absolute value:

abs[x_Real] := If[x < 0, -x, x];
e1 = abs[Sqrt[delta*Cos[theta] - b]]
e1 // Manipulate[Plot[#, {theta, 0, 2 Pi}], {b, 0, 2}, {delta, 0, 2}] &


While the above abs works perfectly with Plot, where the argument x is always Real, the following works in more general situations:

abs[x_?(Element[#, Reals] &)] := If[x < 0, -x, x];

Note the common solution abs[x_?NumericQ] doesn't work with the Manipulate. It generates a Less::nord message about an invalid comparison with a complex number on some inputs.


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.