How to check if a function is convex

50.7k Views Asked by At

According to a calculus book I have been reading, we call a function $g(x)$ a convex function if

$$g(\lambda x +(1-\lambda)y) \leq \lambda g(x) +(1-\lambda)g(y)$$, for all $x,y$ and $0<\lambda<1$.

But if I have to check if a given function is convex or not,this definition seems hard and impractical to use. So,my question is, is there any easier way of checking convexity of a function and if there is,then why it is equivalent to this defiinition.

Thanks in advance!

4

There are 4 best solutions below

4
On BEST ANSWER

What you gave is the standard definition of a convex function.

If $f$ is supposed to be continuous, it is enough to check that

$$f\left(\frac{x+y}{2}\right) \le \frac{f(x)+f(y)}{2}$$ for all $x,y$.

If $f$ is twice differentiable, it is enough to check that the second derivative is non negative.

0
On

For particular functions, there are indeed easier ways of checking.

For example, for any function $g(x)$ which is twice differentiable in an interval $(a,b)$ $$( \forall x\in(a,b) (\frac{d^2g}dx^2 \leq 0) ) \implies g(x) \mbox{ is convex in } (a,b)$$

That is, a function with non-negative second derivative in an interval is convex in that interval.

Another property is that any function $g(x)$ which is not continuous on $(a,b)$ cannot be convex on $(a,b)$.

But there can be other functions which are more difficult to deal with. Suppose $g(x)$ is continuous on $(a,b)$ but is not everywhere differentiable, or has a discontinuous first derivative, so that the second derivative does not exist everywhere. Such a function can still be convex; for example


Somebody changed my answer, saying that a function with a non-positive second derivative is convex. Of course, what one calls "convex" or "concave" for a function from $\Bbb R \to \Bbb R$ is somewhat just a matter of convention, but if you believe that the common usage is the definition found in Wikipedia, the function $x^2$ is convex.

0
On

For convexity of a function $f(x)$ you like to have the graph of your function on an interval [a,b] falls below or on the graph of a straight line segment connecting $f(a)$ and $f(b)$.

You can check arbitrary points or in case the second derivative exist you want your second derivative be non negative.

That makes the slopes to increase and the curve falls above the tangent lines and below the secant lines.

0
On

Check the Hessian matrix of the function. If the matrix is:

  1. Positive-definite then your function is strictly convex.
  2. Positive semi-definite then your function is convex.

A matrix is positive definite when all the eigenvalues are positive and semi-definite if all the eigenvalues are positive or zero-valued.