7
$\begingroup$

I would like to test whether a function is positive over a given interval. Say I have f[x_] = -x^3 + x^2 + 7*x and wanted to know whether it is positive for all x in the interval [0,4]?

It can easily seen by plotting the function that it is not, but I would like to have a more formal test in the form of "TrueForAll[f[x] > 0, {x,0,4}]".

It is probably a trivial problem, but I haven't managed to figure it out myself. So I am grateful for any advice.

$\endgroup$
6
  • 6
    $\begingroup$ Reduce[ForAll[x, 0 <= x <= 4 \[Implies] -x^3 + x^2 + 7*x > 0]]? (Or FullSimplify instead of Reduce.) $\endgroup$
    – Michael E2
    Jan 30, 2016 at 19:56
  • 8
    $\begingroup$ @Michael I think we don't need Implies here: Reduce[ForAll[x, x <= 0 <= 4, f[x] > 0]] $\endgroup$
    – Szabolcs
    Jan 30, 2016 at 20:05
  • $\begingroup$ @Szabolcs I forgot about that form. I hardly ever use ForAll.... $\endgroup$
    – Michael E2
    Jan 30, 2016 at 20:09
  • $\begingroup$ @Szabolcs You have a great solution. Why not post it as an answer? $\endgroup$ Jan 30, 2016 at 20:56
  • $\begingroup$ @Pavlo I was waiting for Michael to do it. $\endgroup$
    – Szabolcs
    Jan 30, 2016 at 21:33

2 Answers 2

13
$\begingroup$

To find the intervals for which f[x] is positive

f[x_] = -x^3 + x^2 + 7*x;

g[x_] = Piecewise[{{f[x], f[x] > 0}}, I];

Plot[{f[x], g[x]}, {x, -3, 4},
 PlotStyle -> {Directive[Red, Dashed], Blue}]

enter image description here

FunctionDomain[g[x], x]

(*  x < (1/2)*(1 - Sqrt[29]) || 
   0 < x < (1/2)*(1 + Sqrt[29])  *)

% // N

(*  x < -2.19258 || 0. < x < 3.19258  *)

EDIT:

Or, more succinctly

FunctionDomain[Piecewise[{{1, f[x] > 0}}, I], x]

(*  x < (1/2)*(1 - Sqrt[29]) || 
   0 < x < (1/2)*(1 + Sqrt[29])  *)
$\endgroup$
1
  • $\begingroup$ Thanks everyone for these extremely helpful answers and comments. Bob Hanlon's answer is great because it provides a more comprehensive picture of the function's characteristics, although it does not perform the True/False test I was looking for. I have found that it can easily be combined with @Michael's and @Szabolcs' approach, however: xpos = FunctionDomain[Piecewise[{{1, f[x] > 0}}, I], x]; Reduce[ForAll[x, 0 <= x <= 4, xpos]] $\endgroup$
    – m.user
    Jan 31, 2016 at 19:28
8
$\begingroup$

I like the answers using Reduce and FunctionDomain. Here's a numerical possibility that uses Minimize to find the global minimum on the domain and tests to see if it's positive.

f[x_] = -x^3 + x^2 + 7*x;
0 <= First@Minimize[{f[x], 0 <= x <= 4}, x]
(* False *)

Alternatively, if needed, you can use NMinimize:

NMinimize[{f[x], 0 <= x <= 4}, x]
(* {-20., {x -> 4.}} *)
0 <= First@NMinimize[{f[x], 0 <= x <= 4}, x]
(* False *)
$\endgroup$

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.