6
$\begingroup$

Please help. Trying to find area between three curves, e^-x, x = 2, y = 1. Can't find out how to plot x = 2. Don't want to use Epilogue unless it can shade the area enclosed by the three curves.

$\endgroup$
  • 2
    $\begingroup$ stackoverflow.com/questions/2897277/… $\endgroup$ – Igor Rivin Sep 12 '14 at 1:15
  • $\begingroup$ gridlines and epilog are the answers to that question - if I'm not mistaken both are done after the initial graphics rendering, meaning that the filling command will continue shading past the point the lines are drawn. I need a solution that will allow me to actually plot the equation x = 2 $\endgroup$ – Cory Sep 12 '14 at 1:19
  • $\begingroup$ A related question is Calling Correct Function for Plotting DiracDelta. Not the same because the plot has value 0 away from the spike. $\endgroup$ – Jens Sep 12 '14 at 5:50
  • 1
    $\begingroup$ Couldn't you use the HeavisideTheta function? Just multiply HeavisideTheta(x-2) by something that is infinite fpr the purposes of your application (i.e. bigger than your visible y-max). One such number could be 100. $\endgroup$ – Christofer Ohlsson Sep 12 '14 at 8:08
11
$\begingroup$

you can also try:

PolarPlot[2/Cos[t], {t, 0, Pi/4}]

or

ContourPlot[x == 2, {x, 0, 4 Pi}, {y, 0, 4 Pi}]

If you want to find the area using other method, I would suggest to use Area and ImplicitRegion in V10 as follows:

r = ImplicitRegion[y >= Exp[-x] && x <= 2 && y <= 1, {x, y}];
Area[r]

(*(1 + E^2)/E^2*)

for shading issue you may find this interesting:

Show[{ContourPlot[{x == 2, y == Exp[-x], y == 1}, {x, -1, 3}, {y, 0, 
    2}], RegionPlot[r, ColorFunction -> "Rainbow"]}]      (*@ Rahul Narain*)

or

Show[{Plot[{Exp[-x], 1}, {x, -2, 3}], 
  PolarPlot[2/Cos[t], {t, 0, 2 \[Pi]}], 
  RegionPlot[r, ColorFunction -> "Rainbow"]}]

enter image description here

$\endgroup$
  • $\begingroup$ Used the advice above. Thank you. $\endgroup$ – Cory Sep 12 '14 at 2:24
  • $\begingroup$ You could combine both the Plot and the PolarPlot into a single ContourPlot in your last example. In any case I feel the PolarPlot form is a little opaque while ContourPlot[x == 2, ...] is perfectly clear. $\endgroup$ – Rahul Sep 12 '14 at 2:50
  • $\begingroup$ @RahulNarain, thanks for the advice. in polar, you know x=rCos[t] or r=x/Cos[t], for this case x=2 and r=2/Cos[t]. $\endgroup$ – Algohi Sep 12 '14 at 2:57
7
$\begingroup$

Its my understanding that you want to insist on using Plot for this problem. Then how about defining a function that has a vertical jump at x=2 and otherwise exceeds the required PlotRange so that its remaining parts won't show up?

Plot[100 Sign[x - 2], {x, -3, 3}, ExclusionsStyle -> Red, 
 PlotRange -> {-1, 1}]

plot

$\endgroup$
  • $\begingroup$ I was about to suggest $MaxMachineNumber might be a good choice for the coefficient 100, but apparently not. (+1) $\endgroup$ – Michael E2 Sep 12 '14 at 2:17
  • $\begingroup$ This works well enough. I'm really surprised there is no plain way to plot a vertical line. Thank you. $\endgroup$ – Cory Sep 12 '14 at 2:23
  • $\begingroup$ Plot[9!(x-2),{x,-3,3},PlotRange->{-3,3}] $\endgroup$ – mathe Sep 12 '14 at 16:23
7
$\begingroup$

The new V10 region functionality is rather suited to implementing your description of the problem in a direct way:

reg = ImplicitRegion[y < 1 && y > E^-x && x < 2, {x, y}];
Show[BoundaryDiscretizeRegion[reg, {{0, 2}, {E^-2, 1}}], Axes -> True,
  AxesOrigin -> {0, 0}, AspectRatio -> 1/GoldenRatio]

Mathematica graphics

Also for finding the area:

RegionMeasure[reg]
(* (1 + E^2)/E^2 *)
$\endgroup$
  • $\begingroup$ There are, except that the OP has pooh-poohed all of them before. $\endgroup$ – Igor Rivin Sep 12 '14 at 3:19
2
$\begingroup$
Show[
 RegionPlot[y > E^-x && y < 1 && x < 2,
  {x, -1, 3}, {y, 0, 1.5}],
 Plot[{
   Tooltip[E^-x, TraditionalForm[y == E^-x]],
   Tooltip[1, TraditionalForm[y == 1]]},
  {x, -1, 3}],
 Epilog -> Tooltip[Line[{{2, 0}, {2, 1.5}}],
   TraditionalForm[x == 2]]]

enter image description here

area = Integrate[1 - E^-x, {x, 0, 2}]

1 + 1/E^2

$\endgroup$
2
$\begingroup$

You might find the answers to an old question on StackOverflow useful

My suggested hack in that case involved Rotate:

ticks = {{None, ({#, Rotate[#, 90 Degree], {0.02, 0}} & /@ 
      Range[0, 4])}, {({#, Rotate[#, 90 Degree], {0.02, 0}} & /@ 
      Range[0, 1, 0.25]), None}};

Rotate[Plot[2, {x, 0, 1}, AspectRatio -> GoldenRatio, 
  AxesOrigin -> {1, 0}, Frame -> True, 
  FrameTicks -> ticks], -90 Degree]

I don't know why the previous version didn't rotate properly.

Of course, since you want to plot x=something and y=something simultaneously, this might not work for you, in which case I'd recommend Jens' answer, or hacking the setting for AxesOrigin to create a horizontal line as well as a vertical one.

$\endgroup$
1
$\begingroup$

ParametricPlot[{10, y}, {x, -10, 10}, {y, -10, 10}] works for me.

$\endgroup$
  • 2
    $\begingroup$ Is there any way to actually plot the equation x = 2, with the Plot function? ParametricPlot is still not what I'm looking for. I'm trying to enclose an area. $\endgroup$ – Cory Sep 12 '14 at 1:30
  • $\begingroup$ No, there is not. $\endgroup$ – Igor Rivin Sep 12 '14 at 1:48
1
$\begingroup$

First we construct some helpers:

f[x_] := E^(-x)

yval = f[2]

1/E^2

h[x_] := 1

v[t_] := 2

Vertical lines can be constructed with ParametricPlot:

ParametricPlot[{v[t], t}
 , {t, yval, 1.}
 , PlotStyle -> {Darker[Red], Thick}
 , PlotRange -> {{-.5, 2.5}, {0, 1.5}}]

enter image description here

Putting it all Together:

Show[Plot[{f[x], h[x]}
  , {x, 0., 2.}
  , Filling -> {2 -> {1}}]
 , ParametricPlot[{v[t], t}
  , {t, yval, 1.}
  , PlotStyle -> {Darker[Red], Thick}]
 , PlotRange -> {{-.5, 2.5}, {0, 1.5}}]

enter image description here

Edit

You can also work with Epilog, Line or Arrow

Plot[{f[x], h[x]}
 , {x, 0, 2}
 , PlotRange -> {{-.5, 2.5}, {0, 1.5}}
 , Epilog -> {Thick, Darker[Red], Line[{{2, yval}, {2, 1}}]}
 , Filling -> {2 -> {1}}
 , Frame -> True
 , Axes -> False
 ]

enter image description here

Plot[{f[x], h[x]}
 , {x, 0, 2}
 , PlotRange -> {{-.5, 2.5}, {0, 1.5}}
 , Epilog -> {Thick, Darker[Red], Arrow[{{2, yval}, {2, 1}}]}
 , Filling -> {2 -> {1}}
 , Frame -> True
 , Axes -> False
 ]

enter image description here

enter image description here

enter image description here

enter image description here

Thx @Jens and @Bob Hanlon for inspiration.

$\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.