3
$\begingroup$

The following code works fine

eqs = {-1 + (3 Subscript[β, 1])/4 == 
    0, -1 + (3 Subscript[β, 2])/4 == 
    0, -1 + (
     2 Subscript[β, 
      1] (-(11/2) + (15 Subscript[β, 2])/2))/(
     9 Subscript[β, 2]) == 
    0, -1 + ((1 + (15 Subscript[β, 1])/4) Subscript[β, 
      2])/(6 Subscript[β, 1]) == 0};
vB = {Subscript[β, 1], Subscript[β, 2]};
 ContourPlot[
 Evaluate[eqs], {Subscript[β, 1], 0, 2}, {Subscript[β, 2],
   0, 2}, ContourStyle -> {Blue, Red, Green, Orange}, 
 PlotLegends -> {"R₀₁ = 1", "R₀₂ = 1", "R₁₂ = 1", "R₂₁ = 1"}, 
 AxesLabel -> {ToString[Subscript[β, 1]], 
   ToString[Subscript[β, 2]]}, 
 PlotLabel -> "Analytical Boundaries"]

but was not working in original version where instead of Subscript[β, 1], Subscript[β, 2] I had vB[[1]], vB[[2]]:

ContourPlot[Evaluate[eqs], {vB[[1]], 0, 2}, {vB[[2]], 0, 2}, 
 ContourStyle -> {Blue, Red, Green, Orange}, 
 PlotLegends -> {"R₀₁ = 1", "R₀₂ = 1", "R₁₂ = 1", "R₂₁ = 1"}, 
 AxesLabel -> {ToString[Subscript[β, 1]], 
   ToString[Subscript[β, 2]]}, 
 PlotLabel -> "Analytical Boundaries"]

In my problem, vB may be any sublist (bifurcation parameters) of a bigger list, and it is disapointing that I cannot plot unless I copy the actual names of the parameters in each case into ContourPlot

$\endgroup$
1
  • $\begingroup$ The reason ContourPlot[] holds its arguments is to localize the variables. It cannot inspect the variable in vB[[1]] without evaluating, so something like @Bob's answer is probably the most convenient, unless one absolutely needs the variables localized. $\endgroup$
    – Michael E2
    Commented 8 hours ago

3 Answers 3

7
$\begingroup$
$Version

(* "14.2.1 for Mac OS X ARM (64-bit) (March 16, 2025)" *)

ContourPlot has the attribute HoldAll. Either add additional Evaluate

ContourPlot[
 Evaluate@eqs,
 Evaluate@{vB[[1]], 0, 2},
 Evaluate@{vB[[2]], 0, 2},
 ContourStyle -> {Blue, Red, Green, Orange},
 PlotLegends -> {"R₀₁ = 1", "R₀₂ = 1", "R₁₂ = 1", "R₂₁ = 1"},
 AxesLabel -> {ToString[Subscript[\[Beta], 1]], ToString[Subscript[\[Beta], 2]]},
 PlotLabel -> "Analytical Boundaries"]

Or let everything evaluate before applying ContourPlot

ContourPlot @@ {eqs, {vB[[1]], 0, 2}, {vB[[2]], 0, 2},
  ContourStyle -> {Blue, Red, Green, Orange},
  PlotLegends -> {"R₀₁ = 1", "R₀₂ = 1", "R₁₂ = 1", "R₂₁ = 1"},
  AxesLabel -> {ToString[Subscript[\[Beta], 1]], 
    ToString[Subscript[\[Beta], 2]]},
  PlotLabel -> "Analytical Boundaries"}

Both produce enter image description here

$\endgroup$
3
$\begingroup$
  • Sequence @@ Thread[{vB, {0, 0}, {2, 2}}] // Evaluate
ContourPlot[Evaluate[eqs],   Sequence @@ Thread[{vB, {0, 0}, {2, 2}}] // Evaluate,   ContourStyle -> {Blue, Red, Green, Orange},   PlotLegends -> {"R₀₁ = 1", "R₀₂ = 1", "R₁₂ = 1", "R₂₁ = 1"},   AxesLabel -> {ToString[Subscript[β, 1]],     ToString[Subscript[β, 2]]},   PlotLabel -> "Analytical Boundaries"]

enter image description here

$\endgroup$
2
$\begingroup$

I thought I'd try to show a way to keep the variables localized. First, I will point out that using Subscript[] makes life hard (see What are the most common pitfalls awaiting new users?, point #3). For instance, the OP's first code fails if beta has a numeric value.

SetAttributes[Subscript, HoldAll];      (* need this because *)
Subscript[\[Beta], 1] = 12;  (* check localization *)
\[Beta] = 777;               (* check localization *)
Hold@                                   (* hold to set up code *)
    ContourPlot[eqs,
     {vB[[1]], 0, 2}, {vB[[2]], 0, 2},
     ContourStyle -> {Blue, Red, Green, Orange}, 
     PlotLegends -> {"R₀₁ = 1", "R₀₂ = 1", "R₁₂ = 1", "R₂₁ = 1"}, 
     AxesLabel -> {ToString[Subscript[\[Beta], 1]], 
       ToString[Subscript[\[Beta], 2]]}, 
     PlotLabel -> "Analytical Boundaries"
     ] /.
   Join[OwnValues@vB, OwnValues@eqs] /. (* substitute values *)
  {HoldPattern[{a_, b_}[[1]]] :> a,     (* manual part extraction *)
   HoldPattern[{a_, b_}[[2]]] :> b} //
 ReleaseHold                            (* release hold *)
Subscript[\[Beta], 1] =.;    (* unset test values *)
\[Beta] =.;

bifurcation plot

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.