Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
    
I have edited your post for proper formatting. In order to see what I did (i.e. how to properly format in code blocks), click the edit button below your post and look at the formatting. Also, click the question mark on the right side of the editing toolbar for further help. Welcome to Mathematica.SE! – march Mar 8 at 17:26
    
Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Mar 8 at 17:38
up vote 6 down vote accepted

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

share|improve this answer
    
thanks m_goldberg---indeed this is easier to understand! – Amanda Mar 8 at 23:46
    
C'est véritablement utile puisque c'est joli. – Dr. belisarius Mar 9 at 3:15
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

share|improve this answer
    
thanks! this is awesome! i appreciate it! – Amanda Mar 8 at 18:34
    
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! – Amanda Mar 8 at 22:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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