Convex Function — Definition, Formula & Examples
A convex function is a function whose graph curves upward, meaning the line segment connecting any two points on the graph never dips below the graph itself. Informally, a convex function "holds water" like a bowl.
A function defined on a convex set is convex if for all and all , the inequality holds. If is twice differentiable, this is equivalent to for all in the domain.
Key Formula
Where:
- = The function being tested for convexity
- = Any two points in the domain
- = A parameter between 0 and 1 that weights the two points
How It Works
To check whether a twice-differentiable function is convex, compute its second derivative and verify that throughout the domain. When everywhere, the function is strictly convex, meaning the chord between any two distinct points lies strictly above the graph. Convexity guarantees that any local minimum is also a global minimum, which is why convex functions are central to optimization. If you cannot compute a second derivative, you can fall back on the definition: pick any two points and check whether the secant line stays on or above the curve.
Worked Example
Problem: Show that is convex using the second-derivative test.
Step 1: Compute the first derivative.
Step 2: Compute the second derivative.
Step 3: Check the sign of the second derivative. Since for all , the condition is satisfied everywhere.
Answer: Because for all , is strictly convex on .
Why It Matters
In machine learning and operations research, convex functions ensure that gradient descent and similar algorithms converge to a global optimum rather than getting stuck at a local one. Many loss functions—such as mean squared error and cross-entropy—are designed to be convex for exactly this reason.
Common Mistakes
Mistake: Confusing convex functions with concave functions based on everyday language. Students sometimes think "convex" means it bulges outward (downward).
Correction: A convex function curves upward (like a cup), meaning . A concave function curves downward (like a cap), meaning . The chord test settles any confusion: if the chord is above the curve, the function is convex.
