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.
10 Answers
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"]}]
-
-
$\begingroup$ You could combine both the
Plot
and thePolarPlot
into a singleContourPlot
in your last example. In any case I feel thePolarPlot
form is a little opaque whileContourPlot[x == 2, ...]
is perfectly clear. $\endgroup$– user484Sep 12, 2014 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$ Sep 12, 2014 at 2:57
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}]
-
$\begingroup$ I was about to suggest
$MaxMachineNumber
might be a good choice for the coefficient100
, but apparently not. (+1) $\endgroup$ Sep 12, 2014 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$– CorySep 12, 2014 at 2:23
-
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]
Also for finding the area:
RegionMeasure[reg]
(* (1 + E^2)/E^2 *)
-
$\begingroup$ There are, except that the OP has pooh-poohed all of them before. $\endgroup$ Sep 12, 2014 at 3:19
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]]]
area = Integrate[1 - E^-x, {x, 0, 2}]
1 + 1/E^2
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]
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.
ParametricPlot[{10, y}, {x, -10, 10}, {y, -10, 10}]
works for me.
-
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$– CorySep 12, 2014 at 1:30
-
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}}]
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}}]
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
]
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
]
Thx @Jens and @Bob Hanlon for inspiration.
Use the GridLines option of the Plot command. You can place a single vertical line anywhere along the x-axis, color it, make it thick or thin, dash it, and maybe even annotate it. Why mess around with sticky equations? Use the built in Plot features. See the GridLines examples.
-
$\begingroup$ Answers (esp. on stack sites such as this one) are supposed to include code and present results. Please add such an example, otherwise this answer will be deemed of low quality and will eventually get deleted after due process. I encourage you to look at the other answers for a representative sample. $\endgroup$– SyedApr 13, 2022 at 6:37
Make an equation with a very steep slope that mimics a verticval line. Be sure to add the PlotRange option to limit the vertical range of the plot. Example with 4 vertical lines:
Plot[{Sin[x], 1*^6 (x - Pi/2), 1*^6 (x - (5 Pi)/2), 1*^6 (x - 9/2 Pi),1*^6 (x - 13/2 Pi)}, {x, 0, 8 Pi}, PlotRange -> {Full, {-2, 2}}]
0
away from the spike. $\endgroup$