0
$\begingroup$

I am trying to show the intersections of two curves, using Epilog. But, Epilog doesn't show the points when I gather them in Table. Is there a way to show the points using a Table?

gamma4 = .4; gamma3 = .284; gamma2 = .265; gamma1 = .484; z3 = 10000; \
z2 = 32000; z1 = 75000; zbar4 = 4800; zbar3 = 20050; zbar2 = 46200;
zbar1 = 138100; h4 = .301; h3 = .404; h2 = .25;
h1 = .045; p1 = 3.89; p2 = 4.92; p3 = 5.22;
p4 = 5.39; g1 = 0; g2 = 0.44; g3 = 0.88; g4 = 1.76;

Cost2 = (g2 + a (g1 p1 + g3 p3 + g4 p4)) h2 (zbar2 - z2) + (g1 + 
      a (g2 p2 + g3 p3 + g4 p4)) h1 (z1 - z2);
Gain2 = (h2 (zbar2 - z2) + 
    h1 (z1 - z2) + (a (g1 p1 + (g2 p2/\[Tau]2) + g3 p3 + g4 p4) - 
       1) h2 zbar2 gamma2 (\[Tau]2/(1 - \[Tau]2)));

"Finding the intersections"

daSol = NSolve[{Cost2 == Gain2}, {\[Tau]2}]
x[aa_] := daSol /. a -> aa ;
y[aa_] := Cost2 /. a -> aa ;

data = Table[{\[Tau]2 /. x[a], y[a]}, {a, 0, 0.05, 0.05}]

Clear[\[Tau]2]

d0 = Show[
  Plot[Evaluate@Table[ Gain2, {a, 0.05, 0.09, 0.01}], {\[Tau]2, 0, 1},
    PlotLabels -> Placed[ Table[a, {a, 0.05, 0.09, 0.01}], After], 
   PlotRange -> {{0, 1}, {0, 11000}}, 
   Epilog -> {PointSize[Large], Red, Point[data]}] , 
  Plot[Evaluate@Table[Cost2, {a, 0.05, 0.09, 0.01}], {\[Tau]2, 0, 1}, 
   PlotLabels -> Placed[ Table[a, {a, 0.05, 0.09, 0.01}], After]]]
$\endgroup$

1 Answer 1

1
$\begingroup$

Update corrected an minor point that managed to stick with me. See bottom of answer.


  • OP's question -- showing points of intersection

The glitch is in data (you didn't flatten the output in daSol).

What happens with daSol containing nested lists is Table[{\[Tau]2 /. x[a], y[a]}, {a, 0, 0.05, 0.05}] results in storing the following in data:

{{{0.561733}, 1562.}, {{0.241936}, 5632.88}}

Notice these aren't coordinates, the "x" value is wrapped in a list which causes the glitch.

Fix goes as follows:

data = Table[{\[Tau]2 /. Flatten[x[a]], y[a]}, {a, 0, 0.05, 0.05}]

d0 = Show[
  Plot[Evaluate@Table[Gain2, {a, 0.05, 0.09, 0.01}], {\[Tau]2, 0, 1}, 
   PlotLabels -> Placed[Table[a, {a, 0.05, 0.09, 0.01}], After], 
   PlotRange -> {{0, 1}, {0, 11000}}, 
   Epilog -> {PointSize[Large], Red, Point @ data}], 
  Plot[Evaluate@Table[Cost2, {a, 0.05, 0.09, 0.01}], {\[Tau]2, 0, 1}, 
   PlotLabels -> Placed[Table[a, {a, 0.05, 0.09, 0.01}], After]]]

yields:

enter image description here

  • But....intersection between what curves for lower point?

Although OP solves for intersection with 0 Gain2 and 0 Cost2, including it as an intersection point for Epilog, and didn't plot those curves. Fixed for my own peace of mind:

d0 = Show[
  Plot[Evaluate@Table[Gain2, {a, 0.05, 0.09, 0.01}], {\[Tau]2, 0, 1}, 
   PlotLabels -> Placed[Table[a, {a, 0.05, 0.09, 0.01}], After], 
   PlotRange -> {{0, 1}, {0, 11000}}, 
   Epilog -> {PointSize[Large], Red, Point@data}], 
  Plot[Evaluate@Table[Cost2, {a, 0.05, 0.09, 0.01}], {\[Tau]2, 0, 1}, 
   PlotLabels -> Placed[Table[a, {a, 0.05, 0.09, 0.01}], After]],
  Plot[{Evaluate@(Cost2 /. a -> 0), 
    Evaluate@(Gain2 /. a -> 0)}, {\[Tau]2, 0, 1}, 
   PlotLabels -> Placed[{0, 0}, After]]]

yielding: enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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