1
$\begingroup$

I have the following function $f$ for NEGATIVE $x$ and I want to use RegionPlot to see the domain of $x$ for which the given function lies between the lines $-1$ and $1$.

f= (((1 + x) Cosh[5 Sqrt[-x]])/(1 - x)) ;

I use this code for Plot:

Plot[  {   - 1,  ((1 + x) Cosh[5 Sqrt[-x]])/(1 - x),  1   }   , {x, 0, -2}, PlotPoints -> 30, PlotRange -> {-10, 10}]

and I get this picture which shows that on a small interval around $x=-1$ the function $f$ lies between the lines $-1$ and $1$.

enter image description here

But then I use RegionPlot by this code

RegionPlot[   - 1 <=   ((1 + x) Cosh[5 Sqrt[-x]])/(1 - x) <=   1    , {y, -3, 3}, {x, 0, -2}, PlotPoints -> 30]

but the resulting plot is empty!

enter image description here

Can someone please explain where I am going wrong? Why does RegionPlot not give the real result?

$\endgroup$
6
  • 1
    $\begingroup$ Well, you're not using y in the predicate to RegionPlot, so I don't think you can get a 2D region. But why are you switching to RegionPlot? What are you trying to do? If you want to see more detail, you can just adjust the x-range in your Plot. $\endgroup$ Commented Jan 11, 2025 at 17:58
  • $\begingroup$ Welcome to Mathematica StackExchange! Either make the x range smaller, or increase PlotPoints: RegionPlot[-1 <= f <= 1, {x, -1.5, -0.5}, {y, -2, 0}] ... RegionPlot[-1 <= f <= 1, {y, -3, 3}, {x, 0, -2}, PlotPoints -> 100]. $\endgroup$ Commented Jan 11, 2025 at 18:01
  • $\begingroup$ Oh, based on @Domen's comment, were you wanting to see the bounding box around the function with those given boundary constraints? I think it'd be nice if you clarified that in your question. $\endgroup$ Commented Jan 11, 2025 at 18:07
  • $\begingroup$ @Domen Thank you; this is what I wanted. $\endgroup$ Commented Jan 11, 2025 at 19:20
  • 1
    $\begingroup$ From the documentation, RegionPlot can in general only find regions of positive measure; it cannot find regions that are just lines or points. Use RegionFunction option in Plot $\endgroup$ Commented Jan 11, 2025 at 21:14

4 Answers 4

3
$\begingroup$
  • ImplicitRegion+ RegionPlot work for this case.
Clear["Global`*"];
f = (((1 + x) Cosh[5 Sqrt[-x]])/(1 - x));
reg = ImplicitRegion[-1 <= ((1 + x) Cosh[5 Sqrt[-x]])/(1 - x) <= 
    1, {{x, -2, 0}, {y, -1, 1}}];
regplot = 
  RegionPlot[reg, PlotRange -> All, 
   PlotStyle -> Directive@{Red, Opacity[.5]}];
Plot[{-1, ((1 + x) Cosh[5 Sqrt[-x]])/(1 - x), 1}, {x, -2, 0}, 
 PlotPoints -> 30, PlotRange -> {-10, 10}, Epilog -> regplot[[1]]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Neat: the big and little picture all in one +1 :) $\endgroup$ Commented Jan 12, 2025 at 2:29
  • $\begingroup$ Just edited a minor spelling error not the code. You give a useful answer rather than mine (which was play). $\endgroup$ Commented Jan 12, 2025 at 2:37
  • $\begingroup$ @ubpdqn Thanks! $\endgroup$ Commented Jan 12, 2025 at 2:50
2
$\begingroup$

Ist this what you want?

f[x_] = (((1 + x) Cosh[5 Sqrt[-x]])/(1 - x));
pred[x_, y_] = -1 <= f[x] <= 1 && -1 <= y <= 1;
RegionPlot[pred[x, y], {x, -1.2, -0.8}, {y, -1.5, 1.5}, Axes -> True]

enter image description here

$\endgroup$
2
$\begingroup$

If have interpreted question correctly the bounding box is sought. I post this for fun.

Here is an approach using MeshShading. It works here as only 2 end-points of a monotonic segment.

f[x_]:= (((1+x) Cosh[5 Sqrt[-x]])/ (1 -x))
Plot[f[x], {x, -2, 0}, PlotRange → {-3, 3}, MeshFunctions → (#2 &), Mesh → {{-1, 1}}, MeshShading → {None, Red, None}] /. Point[a__] :→ {Opacity[0.5], Apply[Rectangle,a]}

enter image description here

Or if you want to “zoom in” just narrow plot range:

enter image description here

$\endgroup$
1
$\begingroup$

Plot with option RegionFunctionworks too

Plot[{-1, ((1 + x) Cosh[5 Sqrt[-x]])/(1 - x), 1}, {x, -2, 0}, 
 PlotPoints -> 30,   
 RegionFunction -> Function[{x, y}, Element [{x, y}, reg]]]

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.