# How can I plot and indicate when the function is positive or negative?

I would like to study the sign of this function (potential) and show the region (positive-negative)

These are the parameters followed by the code (left figure)

a = 1; c = 1;
b = -1; d = 1;
p = 1; q = -1;
f1= (Exp[-2 r a] p)/(2 r c) + (Exp[-2 r b] p)/(2 r  d)
f2= ( Exp[-2 r a] q)/(2 r  c) + (Exp[-2 r b] q)/(2 r d)

Plot[{ f1,f2 } , {r, -2, 2}, PlotRange -> Automatic]


As we see for this case, we obtain different signs for f1 and f2. In four different regions I would like to show them in the plot, A legend it possible only for two regions?

For example, If we change b and d with the same sign (d=-1 and b=-1) (right figure) have only two regions. Please any suggestion and recommendation will be usefull

• Do you mean something like Plot[{f1, f2 } , {r, -2, 2}, ColorFunctionScaling -> False, ColorFunction -> (If[#2 > 0, Blue, Red]&)]? – MarcoB Nov 25 '20 at 6:47

a = 1; c = 1;
b = -1; d = 1;
p = 1; q = -1;
f1 = (Exp[-2 r a] p)/(2 r c) + (Exp[-2 r b] p)/(2 r d);
f2 = (Exp[-2 r a] q)/(2 r c) + (Exp[-2 r b] q)/(2 r d);
a = 1; c = 1;
b = -1; d = 1;
p = 1; q = -1;
f1 = (Exp[-2 r a] p)/(2 r c) + (Exp[-2 r b] p)/(2 r d);
f2 = (Exp[-2 r a] q)/(2 r c) + (Exp[-2 r b] q)/(2 r d);
Plot[{f1, f2}, {r, -2, 2}, PlotRange -> Automatic,
MeshFunctions -> {#1 &,#1*#2 &},
MeshShading -> {{Red, Green}, {Blue, Yellow}}, Mesh -> {{0}}]


Since the sign of $$x$$, $$x y$$ can distinguish the four quadrant, so this method can also be used to ParametricPlot who cross the four quadrant.

ParametricPlot[{t/4 Cos[t], t/4 Sin[t]}, {t, 0, 20},
MeshFunctions -> {#1 &, #1*#2 &},
MeshShading -> {{Red, Green}, {Blue, Yellow}}, Mesh -> {{0}}]


Clear["Global*"]

a = 1; c = 1;
b = -1; d = 1;
p = 1; q = -1;
f1 = (Exp[-2 r a] p)/(2 r c) + (Exp[-2 r b] p)/(2 r d);
f2 = (Exp[-2 r a] q)/(2 r c) + (Exp[-2 r b] q)/(2 r d);

Plot[Evaluate@Outer[
Tooltip@ConditionalExpression[#2, #1] &,
{r > 0, r < 0}, {f1, f2}], {r, -2, 2},
PlotLegends ->
{"f1;\[ThinSpace]r\[ThinSpace]>\[ThinSpace]0",
"f2;\[ThinSpace]r\[ThinSpace]>\[ThinSpace]0",
"f1;\[ThinSpace]r\[ThinSpace]<\[ThinSpace]0",
"f2;\[ThinSpace]r\[ThinSpace]<\[ThinSpace]0"}]
`