6
$\begingroup$

I am trying to shade the area bounded by the lines $y=2$, $y=-x+2$ and the parabola $y=x^2$. The plot is shown below. The area I'm talking about is the that bounded by the 4 black points. I am trying to shade it and I don't know how. Your assitance is appreciated.

Plot[{2 - x, x^2, 2}, {x, -3, 3}, PlotRange -> {-1, 5}, 
     PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}},  
     Epilog -> {Black, PointSize[0.025], Point[pts]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Show[ RegionPlot[y < 2 && y < 2 - x && y > x^2, {x, -2, 2}, {y, -1, 3}], Plot[{2 - x, x^2, 2}, {x, -3, 3}]] $\endgroup$
    – Kuba
    Oct 27 '14 at 23:45
  • 2
    $\begingroup$ @Kuba Show[RegionPlot[Min[2, 2 - x] > y > x^2, {x, -2, 2}, {y, -1, 3}], Plot[{2 - x, x^2, 2}, {x, -3, 3}]] $\endgroup$ Oct 28 '14 at 0:06
6
$\begingroup$
pts = {{-Sqrt@2, 2}, {1, 1}, {0, 2}, {0, 0}};
opts = {PlotRange -> {-1, 5}, PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}}, 
        Epilog -> {Black, PointSize[0.025], Point[pts]}, 
        Filling -> {3 -> {{2}, {Transparent, Lighter@Lighter@Blue}}}};
Show[
 Plot[{2 - x, x^2, 2}, {x, -3, 0}, Evaluate@opts],
 Plot[{2, x^2, 2 - x}, {x, 0, 3}, Evaluate@opts], PlotRange -> All]

Mathematica graphics

$\endgroup$
0
7
$\begingroup$
Plot[{2 - x, x^2, 2}, {x, -3, 3}, PlotRange -> {-1, 5}, 
 PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}},
 Prolog -> 
  First@Show@
    BoundaryDiscretizeRegion[
     ImplicitRegion[y <= 2 - x && y <= 2 && y >= x^2, {x, y}]]
 ]

Mathematica graphics


Someday

BoundaryDiscretizeRegion[
 ImplicitRegion[y <= 2 - x && y <= 2 && y >= x^2, {x, y}]]["GraphicsComplex"]

will work reliably.

$\endgroup$
1
  • 1
    $\begingroup$ "some day" I'll have v10. +1 :) $\endgroup$ Oct 28 '14 at 0:00
5
$\begingroup$
Plot[{ConditionalExpression[x^2, x^2 <= Min[2, 2 - x]], Min[2, 2 - x],2 - x, 2, x^2}, {x, -3, 3}, 
 Filling -> {1 -> {2}}, FillingStyle -> Yellow, 
 PlotStyle -> {Directive[{Opacity[1], Yellow}], Opacity[0], 
   Directive[{Opacity[1], Red}], Green, Directive[{Dashed, Orange}]}, BaseStyle -> Thick]

enter image description here

Use MeshFunctions and Mesh to add the intersection points

Plot[{ConditionalExpression[x^2, x^2 <= Min[2, 2 - x]], Min[2, 2 - x],
   2 - x, 2, x^2}, {x, -3, 3},
 Filling -> {1 -> {2}}, FillingStyle -> Yellow, 
 Mesh -> {{0}, {0}}, MeshStyle -> PointSize[.03],
 MeshFunctions -> {# &, ConditionalExpression[Min[2, 2 - #] - #^2, #2 + # <= 2 && #2 <= 2] &}, 
 PlotStyle -> {Directive[{Opacity[1], Yellow}], Opacity[0], 
   Directive[{Opacity[1], Red}], Green, Directive[{Dashed, Orange}]}, 
 BaseStyle -> Thick]

enter image description here

ParametricPlot[{ConditionalExpression[{x, v x^2 + (1-v) Min[2, 2 - x]}, x^2 <= Min[2, 2 - x]], 
 {x, 2 - x}, {x, 2}, {x, x^2}}, {x, -3, 3}, {v, 0, 1}, 
 AspectRatio -> 1/GoldenRatio, PlotStyle -> ColorData[1, "ColorList"], 
 BaseStyle -> Thick, Frame -> False, Axes -> True, Mesh -> None]

enter image description here

$\endgroup$
2
  • $\begingroup$ Perhaps if you put the ConditionalExpression first its boundaries will be overwritten by the other plots, instead of the other way around. $\endgroup$
    – Michael E2
    Oct 28 '14 at 0:21
  • $\begingroup$ Thank you @Michael, very good point. $\endgroup$
    – kglr
    Oct 28 '14 at 0:32
1
$\begingroup$
pts = {{-Sqrt@2, 2}, {1, 1}, {0, 2}, {0, 0}};
prolog = Plot[{x^2, Piecewise[{{2 - x, x > 0}, {2, x < 0}}]}, 
    {x, -Sqrt@2, 1}, Filling -> {1 -> {2}}][[1]];

I have applied prolog with Piecewise

Plot[{2 - x, x^2, 2}, {x, -3, 3}, PlotRange -> {-1, 5}, 
    PlotStyle -> {{Red, Thick}, {Dashed}, {Blue, Thick}},
    Prolog -> prolog, 
    Epilog -> {Black, PointSize[0.025], Point[pts]}
]

Blockquote

$\endgroup$

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.