Convex Function

Author

Eric W. Weisstein
September 12, 2005

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Topology/ConvexFunction.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/ConvexFunction.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Code

ConvexQ[f_,reg_:{-∞,∞}]:=Module[{x1,x2,λ},Resolve[ForAll[{x1,x2,λ},
0<λ<1&&reg[[1]]<x1<reg[[2]]&&reg[[1]]<x2<reg[[2]],
f[λ x1+(1-λ)x2]≤λ f[x1]+(1-λ)f[x2]
],Reals]
]

Examples

(x^p)

Table[ConvexQ[#^n&],{n,6}]//Timing

x log(x)

ConvexQ[# Log[#]&,{0,∞}]

ConvexQ[Abs[#]&]