Function Repository Resource:

MonotonicFunctionQ

Source Notebook

Check if a function is monotonic

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["MonotonicFunctionQ"][f,x]

gives True if f is monotonic with respect to x.

ResourceFunction["MonotonicFunctionQ"][f,x,dir]

restricts the test to the direction dir.

Details and Options

The direction dir can be any of Automatic, "Increasing" or "Decreasing" and defaults to Automatic. When dir is Automatic, ResourceFunction["MonotonicFunctionQ"] returns True if f is increasing or decreasing.
ResourceFunction["MonotonicFunctionQ"] expects f to be a univariate expression in terms of x, similar to what might be used in Plot.
ResourceFunction["MonotonicFunctionQ"] returns True based on the definition of f being monotonic; that is, f is increasing on an interval A if for all {x,y}A such that x<y, it is the case that f[x]f[y].

Examples

Basic Examples (2) 

Compute whether an expression is monotonic:

In[1]:=
ResourceFunction["MonotonicFunctionQ"][x^3, x]
Out[1]=

Determine if an expression is increasing:

In[2]:=
ResourceFunction["MonotonicFunctionQ"][x^5, x, "Increasing"]
Out[2]=

Properties and Relations (3) 

Note that a function with regions where it is constant may still be considered increasing:

In[3]:=
f = Piecewise[{{x, x <= 0}, {0, 0 < x < 1}, {x - 1, x > 1}}];
In[4]:=
ResourceFunction["MonotonicFunctionQ"][f, x]
Out[4]=

For more information on the monotonicity of the input expression, use the resource function FunctionMonotonicity:

In[5]:=
ResourceFunction["FunctionMonotonicity"][f, x]
Out[5]=

Such a curve is not strictly monotonic though:

In[6]:=
ResourceFunction["StrictlyMonotonicFunctionQ"][f, x]
Out[7]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 29 September 2020

Related Resources

Author Notes

To view the full source code for MonotonicFunctionQ, run the following code:

In[1]:=
FileNameJoin[
  ReplacePart[
   FileNameSplit[FindFile["ResourceFunctionHelpers`"]], -1 -> "FunctionMonotonicityConcavity.wl"]] // SystemOpen

License Information