1
$\begingroup$

I want to see the domain in which function $f$ is positive. I use this code

f := (7 + 10 x^2 - x^4 + (3 + x^2)^2 Cos[2 x]) Sin[ x]^2 ;
Plot[If[f > 0, 0], {x, 0, 1000}, 
 PlotStyle -> {Automatic, Directive[Thickness[.01], Red]}, 
 PlotPoints -> 5000, WorkingPrecision -> 10, MaxRecursion -> 6]

enter image description here

but when I increase the value of PlotPoints, I see that the red parts are increasing continuously. How can I know the maximum value of PlotPoints which gives me the whole result (all the positive part)? Especially when I need to see data for a very large number of x.

$\endgroup$

2 Answers 2

4
$\begingroup$
Clear["Global`*"]

f := (7 + 10 x^2 - x^4 + (3 + x^2)^2 Cos[2 x]) Sin[x]^2;

The domain is

dom = Reduce[{f > 0, 0 <= x <= 1000}, x];

Looking at the first few intervals in the domain

dom[[1 ;; 5]]

enter image description here

The number of intervals is

Length@dom

(* 637 *)

Use NumberLinePlot

NumberLinePlot[dom, x]

enter image description here

This is too dense to be meaningful. Looking at a small region

NumberLinePlot[dom, {x, 0, 10}]

enter image description here

$\endgroup$
6
  • $\begingroup$ Thanks. So, this command NumberLinePlot[dom, x] gives the whole results, right? $\endgroup$
    – charmin
    Nov 3, 2020 at 17:15
  • 1
    $\begingroup$ Yes. dom is the whole result and the plot displays dom $\endgroup$
    – Bob Hanlon
    Nov 3, 2020 at 17:41
  • $\begingroup$ Thanks. But I get this error for dom command: "This system cannot be solved with the methods available to Reduce. >>" $\endgroup$
    – charmin
    Nov 3, 2020 at 17:48
  • $\begingroup$ What version of Mathematica are you using? $\endgroup$
    – Bob Hanlon
    Nov 3, 2020 at 17:56
  • 1
    $\begingroup$ I do not have that version. Try looking at a smaller interval, e.g., xmin = 0; dom = Reduce[{f > 0, xmin <= x <= xmin + 20}, x]; NumberLinePlot[dom, {x, xmin, xmin + 20}] You could also use Manipulate to control xmin $\endgroup$
    – Bob Hanlon
    Nov 3, 2020 at 18:10
0
$\begingroup$

Maybe we should split the the domain of definition into several intervals.

domMax = 100;
sols = Reduce[(7 + 10 x^2 - x^4 + (3 + x^2)^2 Cos[2 x]) Sin[x]^2 > 0 &&
      0 <= x <= domMax, x, Reals] // N;
Table[Plot[{(7 + 10 x^2 - x^4 + (3 + x^2)^2 Cos[2 x]) Sin[x]^2, 0}, 
  x ∈ ImplicitRegion[sols[[i]], x], PlotStyle -> {Blue, Red},
   TicksStyle -> Directive["Label", Tiny]], {i, Length@sols}]

enter image description here

Explain the above codes.

we use Reduce to find all the interval which the function is positive. For example, the first interval is 0. < x < 1.38363,the second interval is 2.0214 < x < 3.14159 etc.

An then we can Plot function by using the x ∈ ImplicitRegion to set the range of function.

Plot[(7 + 10 x^2 - x^4 + (3 + x^2)^2 Cos[2 x]) Sin[x]^2, 
 x ∈ ImplicitRegion[0. < x < 1.38363, x]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks. Could you please explain more? $\endgroup$
    – charmin
    Nov 3, 2020 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.