1
$\begingroup$

Can two parametric curves as functions of different parameters be plotted in the same ParametricPlot3D without Show? Currently it throws an error "[some number] is not a valid variable" (plot4 in the code below). The curves separately can be plotted (plot2, plot3 in the code below). Show can display the two in the same plot.

Clear[d1, d2, q1, q2, pi1, pi2, p1br, p2br, cdf, c1, c2, p1, p2, \
\[Alpha], \[Beta], \[Gamma], br1, br2, pi1opt, pi2opt, plot1, plot2, \
plot3]
$Assumptions = 
  0 < q1 < q2 && 0 <= c1 <= c2 && c1 <= p1 < p2 && 
   c2 <= p2 < \[Beta]*q2 && (p2 - p1)*q1 >= p1*(q2 - q1) && 
   p1 < q1*\[Beta] && 0 <= \[Alpha] < \[Gamma] < \[Beta];
cdf[v_] = 
  Piecewise[{{0, 
     v < \[Alpha]}, {(v - \[Alpha])^2/((\[Beta] - \[Alpha])*(\[Gamma] \
- \[Alpha])), \[Alpha] <= 
      v < \[Gamma]}, {1 - (\[Beta] - 
      v)^2/((\[Beta] - \[Alpha])*(\[Beta] - \[Gamma])), \[Gamma] \
<= v <= \[Beta]}, {1, v > \[Beta]}}];
d1[p1_, p2_, q1_, q2_] = Max[0, cdf[(p2 - p1)/(q2 - q1)] - cdf[p1/q1]];
d2[p1_, p2_, q1_, q2_] = 1 - cdf[Max[p2/q2, (p2 - p1)/(q2 - q1)]];
pi1[p1_, p2_, q1_, q2_] = (p1 - c1)*d1[p1, p2, q1, q2];
pi2[p1_, p2_, q1_, q2_] = (p2 - c2)*d2[p1, p2, q1, q2];
\[Alpha] = 0; \[Beta] = 1; \[Gamma] = 0.5; q1 = 1; q2 = 2; c1 = 0; c2 \
= 0.5;
br1[p2_] = br1[p2_?NumericQ] := NArgMax[pi1[p1, p2, q1, q2], p1]
br2[p1_] = br2[p1_?NumericQ] := NArgMax[pi2[p1, p2, q1, q2], p2]
pi1opt[p2_] = 
 pi1opt[p2_?NumericQ] := NMaxValue[pi1[p1, p2, q1, q2], p1]
pi2opt[p1_] = 
 pi2opt[p1_?NumericQ] := NMaxValue[pi1[p1, p2, q1, q2], p2]
plot2 = ParametricPlot3D[{p1, br2[p1], pi2opt[p1]}, {p1, 
    c1, \[Beta]*
     q1}
   , 
   AxesLabel -> {Subscript[P, 1], Subscript[P, 2], Subscript[\[Pi], 
 2]}];
plot3 = ParametricPlot3D[{br1[p2], p2, pi1opt[p2]}, {p2, 
    c2, \[Beta]*q2}, 
   AxesLabel -> {Subscript[P, 1], Subscript[P, 2], Subscript[\[Pi], 
     1]}];
plot4=ParametricPlot3D[{{br1[p2],p2,pi1opt[p2]},{p1,br2[p1],pi2opt[\
p1]}},{p1,c1,\[Beta]*q1},{p2,c2,\[Beta]*q2}](*empty plot, "not a \
valid variable"*)
$\endgroup$
2
  • 3
    $\begingroup$ If br1[p2_] = br1[p2_?NumericQ] := NArgMax[...] and similar are intended to be memorization you have the syntax wrong. It would be br1[p2_?NumericQ] := br1[p2] = NArgMax[...] $\endgroup$ – Bob Hanlon Mar 21 '20 at 17:02
  • $\begingroup$ Thanks @BobHanlon! That was my intention indeed. $\endgroup$ – Sander Heinsalu Mar 21 '20 at 19:09
3
$\begingroup$

Update: Perhaps this makes more sense:

ClearAll[path1b, path2b, prjbr1, prjbr2]
path1b[p_?NumericQ] := ConditionalExpression[{p, br1@p, pi1opt[p]}, c2 <= p <= β q2]
path2b[p_?NumericQ] := ConditionalExpression[{br2@p, p, pi2opt[p]}, c1 <= p <= β q1]
prjbr1[p_?NumericQ] := ConditionalExpression[{p, br1@p, 0}, c2 <= p <= β q2]
prjbr2[p_?NumericQ] := ConditionalExpression[{br2@p, p, 0}, c1 <= p <= β q1]

ParametricPlot3D[{path1b[w], path2b[w], prjbr1[w], prjbr2[w]}, 
 {w, Min[c1, c2], β*Max[q1, q2]}, 
 PlotStyle -> ({##, Directive[Dashed, #], Directive[Dashed, #2]} & @@  
    (ColorData[97] /@ {1, 2})), 
 BoxRatios -> 1, PlotRange -> All, 
 AxesLabel -> {Row[Style[#, 16] & /@ {Subscript[P, 1], BR1[Subscript[P, 2]]}, ","], 
   Row[Style[#, 16] & /@ {Subscript[P, 2], BR2[Subscript[P, 1]]}, ","], 
   Row[Style[#, 16] & /@ {Subscript[π, 1], Subscript[π, 2]}, ","]}, 
 ImageSize -> Large]

enter image description here

Original answer:

ClearAll[path1, path2]
path2[p_?NumericQ] := {br2@#, #, pi2opt[#]} & @ Rescale[p, {c2, β*q2}, {c1, β*q1}]
path1[p_?NumericQ] := {p, br1@p, pi1opt[p]}

ParametricPlot3D[{path1[w], path2[w]}, {w, c2, β*q2}]

enter image description here

Showing the best response functions as projections:

ParametricPlot3D[{path1[w], path2[w], Append[path1[w][[;; 2]], 0], 
  Append[path2[w][[;; 2]], 0]}, {w, c2, β*q2}, 
 PlotStyle -> ({##, Directive[Dashed, #], Directive[Dashed, #2]} & @@ 
    (ColorData[97] /@ {1, 2})), 
 BoxRatios -> 1, PlotRange -> All, 
 AxesLabel -> {Row[Style[#, 16] & /@ {Subscript[P, 1], BR1[Subscript[P, 2]]}, ","], 
   Row[Style[#, 16] & /@ {Subscript[P, 2], BR2[Subscript[P, 1]]}, ","], 
   Row[Style[#, 16] & /@ {Subscript[π, 1], Subscript[π, 2]}, ","]}, 
   ImageSize -> Large]

enter image description here

$\endgroup$
3
  • $\begingroup$ Elegant. To check that I understand what is happening (to modify in the future): {br2@#, #, pi2opt[#]} & defines a function for one curve in 3D. The Rescale stretches it before it is assigned to path2. (Vaguely, the stretch could be undesirable for what I'm trying to do because it may move the intersection of the curves. br2 is already in "inverse function" form. But this is not a problem with the answer.) Then path1 applies br1 to p. I do not understand why, but I trust the Evaluate in the plot is necessary. $\endgroup$ – Sander Heinsalu Mar 21 '20 at 16:27
  • 1
    $\begingroup$ @Sander, we are rescaling the _argument _ (w) of br2[w] , w and pi2opt[w] to run from c1, to β*q1 as w varies from c2, to β*q2. Removed Evaluate as it is not necessary in this case. $\endgroup$ – kglr Mar 21 '20 at 18:30
  • $\begingroup$ I am learning a lot of plotting from this answer: ConditionalExpression,BoxRange. The axis labelling and PlotStyle have some advanced commands I do not yet understand. $\endgroup$ – Sander Heinsalu Mar 22 '20 at 2:10

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.