11
$\begingroup$

I have three functions, U1, U2, Dead. I would like to fill the area between the three curves when U2 is (only) above both U1 and Dead. This raises two issues relative to what I can find online. One is dealing with three vs. two curves filling and one is that the filling ends up only on a region. (I can find some things online on the latter---but I need a solution that works with the three curves.)

To be more specific: the functions are

U1[del_] = (1 - del)/del
U2[del_] = del
Dead[del_] = del*del*del

and right now I have

Plot[{U1[del], U2[del], Dead[del]},
   {del, 0, 1},
   PlotRange -> {0, 1}, 
   PlotStyle -> {{Blue, Dashed, Thick}, {Red, Dashed, Thick}, {Green, Dashed, Thick}},
   Filling -> {2 -> {3}},
   Frame -> True]

Mathematica graphics

This filled between U2 and Dead. But I want the filling to be between U2 and Max[U1, Dead] and only when U2 is above the max.

Any help would be appreciated. Apologies if I am writing in the wrong format---I am new. Thanks!

$\endgroup$
0

2 Answers 2

7
$\begingroup$

I strongly applaud Dr. belisarius' use of an invisible curve to control the filling, but I think the following implementation of his idea is easier to understand.

U1[del_] := (1 - del)/del
U2[del_] := del
Dead[del_] := del^3

controlCurve[del_] :=
  Piecewise[
    {{U2[del], U1[del] > U2[del]},
     {U1[del], U1[del] > Dead[del]}},
    Dead[del]]

Plot[{U1[del], U2[del], Dead[del], controlCurve[del]}, {del, 0, 1}, 
  PlotRange -> {0, 1},
  PlotStyle ->
    {{Blue, Dashed, Thick}, {Red, Dashed, Thick}, 
     {Green, Dashed, Thick}, Transparent},
  Filling -> {2 -> {{4}, Yellow}},
  Frame -> True]

plot

$\endgroup$
2
  • $\begingroup$ thanks m_goldberg---indeed this is easier to understand! $\endgroup$
    – Amanda
    Mar 8, 2016 at 23:46
  • $\begingroup$ C'est véritablement utile puisque c'est joli. $\endgroup$ Mar 9, 2016 at 3:15
10
$\begingroup$
f[s_] := Plot[{U1[del], U2[del], Dead[del], 
              If[s[U2[del], #], #, U2[del]] &@Max[U1[del], Dead[del]]}, 
              {del, 0, 1}, PlotRange -> {0, 1}, 
              PlotStyle -> {{Blue, Dashed, Thick},
                           {Red, Dashed, Thick}, 
                           {Green, Dashed, Thick}, 
                            Transparent}, 
              Filling -> {2 -> {4}}, Frame -> True]

f /@ {Less, Greater}

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ thanks! this is awesome! i appreciate it! $\endgroup$
    – Amanda
    Mar 8, 2016 at 18:34
  • $\begingroup$ May I bother you with a follow up: Would it be possible to explain the role of the "#" in this bit: If[s[U2[del], #], #, U2[del]] &@Max[U1[del], Dead[del]]}? Just want to understand/learn. Thanks again! $\endgroup$
    – Amanda
    Mar 8, 2016 at 22:05

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.