2
$\begingroup$

I have the following function

f[z_] := Piecewise[{{Cos[z] - 17 Sin[z]/z, z > 0}, {Cosh[z] - 17 Sinh[z]/z, z <= 0}}]

I am interested in the regions where $\vert f(z)\vert \leq 1$, I tried to shade that region using Filling, but my results were not the expected, how should I write the code? Here is my attempt:

Plot[{f[z], -1, 1}, {z, -5, 20}, PlotStyle -> {Automatic, Dashed, Dashed}, Filling -> {1 -> {3}}]

enter image description here

To be more precise: I want to shade the region $D=\{(x,y):\vert f(x) \vert<1\text{ and } \vert y \vert <1 \}$

$\endgroup$
4
  • $\begingroup$ Is this not what you want: Filling -> {2 -> {3}} ? $\endgroup$ – Arnoud Buzing Apr 17 '20 at 20:58
  • 1
    $\begingroup$ does Plot[{f[z], ConditionalExpression[f[z], -1 < f[z] < 1], -1, 1}, {z, -25, 20}, PlotStyle -> {Automatic, None, Dashed, Dashed}, Filling -> {2 -> {{3}, Cyan}, 2 -> {{4}, Cyan}}, PlotPoints -> 100] give what you need? $\endgroup$ – kglr Apr 17 '20 at 22:20
  • $\begingroup$ .. or Plot[{f[z], ConditionalExpression[f[z], -1 < f[z] < 1], -1, 1}, {z, -25, 20}, PlotStyle -> {Automatic, None, Dashed, Dashed}, Filling -> {2 -> {Axis, Cyan}}, PlotPoints -> 100]? $\endgroup$ – kglr Apr 17 '20 at 22:21
  • $\begingroup$ @kglr Yes! That is what I wanted, Thanks! $\endgroup$ – Victor Gustavo May Apr 17 '20 at 22:22
1
$\begingroup$
Plot[{f[z], ConditionalExpression[f[z], -1 < f[z] < 1], -1, 1}, {z, -25, 20}, 
 PlotStyle -> {Automatic, None, Dashed, Dashed}, 
 Filling -> {2 -> {{3}, Cyan}, 2 -> {{4}, Cyan}}, PlotPoints -> 100]

enter image description here

Also

Plot[{f[z], Clip[f[z], {-1, 1}, {Null, Null}], -1, 1}, {z, -25, 20}, 
 PlotStyle -> {Automatic, None, Dashed, Dashed}, 
 Filling -> {2 -> {{3}, Cyan}, 2 -> {{4}, Cyan}}, PlotPoints -> 100]

same picture

$\endgroup$
1
$\begingroup$

If the answer to my question in the comments is 'no', then perhaps this:

Plot[{f[z], Clip[f[z]], -1, 1}, {z, -25, 20}, 
 PlotStyle -> {Automatic, None, Dashed, Dashed}, 
 Filling -> {2 -> Axis}]

enter image description here

$\endgroup$
1
  • $\begingroup$ This is not quite what I am looking for, I edited my question to be more precise regarding the region I wish to shade $\endgroup$ – Victor Gustavo May Apr 17 '20 at 21:47

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.