2
$\begingroup$

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

enter image description here

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

$\endgroup$
1
  • $\begingroup$ Do you mean something like Plot[{f1, f2 } , {r, -2, 2}, ColorFunctionScaling -> False, ColorFunction -> (If[#2 > 0, Blue, Red]&)]? $\endgroup$ – MarcoB Nov 25 '20 at 6:47
5
$\begingroup$
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}}]

enter image description here

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

enter image description here

$\endgroup$
4
$\begingroup$
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"}]

enter image description here

$\endgroup$

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.