# Restricting a plotted expression to reals in a Manipuate

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.

### EDIT

example function

e1 = Abs[Sqrt[delta*Cos[theta] - b]]
e1 // Manipulate[Plot[#, {theta, 0, 2 Pi}], {b, 0, 2}, {delta, 0, 2}] &

• Dan, Would you include some code so we know the specific function you are working with? – DavidC Apr 9 '13 at 0:34
• 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. – Dan G Apr 9 '13 at 1:07
• I updated the question with a simplified function – Dan G Apr 9 '13 at 1:14

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


Edit:

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.