# Filling the area between two curves, only where and if the second lies above the first one [duplicate]

I would like to make a filling of a plot between two curved dynamically.I have two lines depending upon parameters. They may cross one another, and may not in different domains of the parametric space. I would like to plot them and make filling between these lines, but only if the line 2 lies above the line one, and not otherwise. To be specific, consider a simplistic example:

 k = -0.5;
Plot[{0.5*x^2, x^2 + k}, {x, -2, 2}, Filling -> {1 -> {2}}]


here k is parameter. This yields the expected plot where the area between the two curves is filled everywhere. I need, however, that it would be filled only at x>1 and x<-1. Further I would like to wrap all this with Manipulate statement varying k to have all in dynamics. In addition the real problem that I have is rather complex. These two curves can have none or multiple intersection points depending upon parameters. Thus, the idea to divide the curves into parts between points does not help. This:

    k = -0.5;
Plot[{0.5*x^2, x^2 + k}, {x, -2, 2},
Filling -> If[0.5*x^2 < x^2 + k, {1 -> {2}}]]


makes no filling. Any other ideas?

## marked as duplicate by m_goldberg, Öskå, Simon Woods, Mr.Wizard♦Sep 7 '14 at 12:48

• Filling -> {1 -> {{2}, {Automatic, None}}} ? – Simon Woods Sep 7 '14 at 10:43
• I agree that there is no practical difference between my question and the one pointed out above – Alexei Boulbitch Sep 8 '14 at 8:30

You can use a specification in the following format (explained under Details in Filling):

ik -> {pk, {gk-, gk+}}


Then

Plot[{0.5*x^2, x^2 + k}, {x,-2,2}, Filling -> {1 -> {{2}, {None, Red}}}]


This also works as desired with Manipulate, e.g.

Manipulate[
Plot[{0.5*x^2, x^2 + k}, {x, -2, 2}, Filling -> {1 -> {{2}, {None, Red}}}],
{k, -1, 1}]