calculus and analysis - What is the range of values $x$ for which $f(x)$ is higher than $k$ over a given domain?
What is the easiest way to answer the following question in Mathematica:
Given a function $f(x)=y$, what is the range of values $x$ for which $y$ is higher than some number $k$ over the domain of $x$ $[a;b]$?
For example consider the function:
What is the range of values of $x$, for which $f(x)$ is greater than $k=4.8$ over the domain [-2;2]?
As I am aiming to apply this method to a complicated function, I would like numerical approximations rather than an analytical solution.
Answer
Let
f[x_] := Sin[3 x^2] + x;
and criterion k = 1
, all in the range [-2,2]
.
One can use Solve[]
, NSolve[]
or FindRoot[]
to get crossing points, but it helps to search for solutions using a number of starting points.
myCrossings = Sort@DeleteDuplicates[(x /. FindRoot[f[x] == 1, {{x, Range[-2, 2, .4]}}])]
Then, include the lower and upper limit of your x
range:
PrependTo[myCrossings, -2];
AppendTo[myCrossings, 2]
Then, depending upon whether the value of f[x]
at the lower limit of the range is greater or less than the criterion (here, k = 1
), choose pairs of crossing points for the corresponding ranges of x
:
If[f[-2] > 1, Partition[myCrossings, 2, 2], Partition[Drop[myCrossings, 1], 2, 2]]
(* {{0.443523, 1.02785}, {1.39912, 1.86883}, {1.94362, 2}} *)
If you want a more easily readable output:
#[[1]] < x < #[[2]] & /@ If[f[-2] > 1, Partition[myCrossings, 2, 2], Partition[Drop[myCrossings, 1], 2, 2]]
(* {0.443523 < x < 1.02785, 1.39912 < x < 1.86883, 1.94362 < x < 2} *)
It is true, in the extremely unlikely case that you have a local maximum or local minimum of f[x] at a root--and thus f[x] remains below the criterion or remains above the criterion on both sides of the root--you might have to check for solution ranges.
Comments
Post a Comment