0

I was trying to make a Plot of three functions, however, its output (below) is very different from what I expected.

enter image description here

There are two problems with this plot: first, it seems to be plotting just one function, as all three lines are of the same color. Second, the plot seems to be cut at around 1400.

My code is

p = {1/5, 1/4, 2/3};
v = {0, 6, 15};
u = 10;
eU = Table[p[[i]] Sqrt[wB] + (1 - p[[i]]) Sqrt[wM] - v[[i]], {i, 1, 3}];
Plot[Flatten[Table[wM /. Solve[eU[[i]] == u, {wM}], {i, 1, 3}]], {wB, 0, 1800}]

If, instead, I compute

Flatten[Table[wM /. Solve[eU[[i]] == u, {wM}], {i, 1, 3}]]

and paste the output into a Plot instruction

Plot[{1/16 (2500 - 100 Sqrt[wB] + wB), 1/9 (4096 - 128 Sqrt[wB] + wB),5625 - 300 Sqrt[wB] + 4 wB}, {wB, 900, 1500}]

I do get what I anticipated.

enter image description here

Patricio
  • 583
  • 2
  • 11

1 Answers1

1
$Version

(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)

Clear["Global`*"]

p = {1/5, 1/4, 2/3};
v = {0, 6, 15};
u = 10;

Because the basic operations are Listable, the definition for eU can be written more simply as

eU = p*Sqrt[wB] + (1 - p)* Sqrt[wM] - v; 

Because of the square roots, the solutions are conditional

wMval = SolveValues[# == u, wM, Reals] & /@ eU

enter image description here

Plot[Evaluate[Tooltip[wMval]], {wB, 0, 1800}, 
 PlotLegends -> Placed[Automatic, {0.75, 0.5}]]

enter image description here

Note that the third plot cuts off within the plot range (at 5625/4, i.e., 1406.25)

Alternatively, you could use ContourPlot

ContourPlot[Evaluate@Thread[eU == 10], {wB, 0, 1800}, {wM, 0, 850},
 AspectRatio -> 1/GoldenRatio,
 PlotPoints -> 50,
 MaxRecursion -> 3,
 PlotLegends -> Placed[Automatic, {0.75, 0.5}]]

enter image description here

Again note the cutoff of the third plot within the plot range.

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • I imagined there was a better way of defining eU. Very helpful. Also, very nice the conditional solutions, I was doing it by hand. – Patricio Mar 17 '22 at 07:09