Convex sets and convex functions
The question
What can a straight segment tell you about a region or a curve?
Place a point between two endpoints, then decide what the segment reveals.
- 1 SeeClassify regions and graphs.
- 2 TryMove a point along a chord.
- 3 ProveConnect a function to a set.
- 4 ApplyTest constraints and model costs.
Before you start · 3 quick checks on vector arithmetic, evaluating a function, and reading an inequality
Two ideas before you start
2 ideasA weight picks a point on a segment
Two marked endpoints and a point between them. The point moves when you choose a weight.
Use the same pair of weights for every coordinate. The resulting point slides from the first endpoint to the second.
Exact definition
Let \(u,v\) be points of \(\mathbb R^n\), the space of real vectors with \(n\) coordinates. For a real weight \(0\le t\le 1\), the point \(z=(1-t)u+tv\) is a convex combination of \(u\) and \(v\). The weights are nonnegative and sum to one. The closed segment is the set of all such \(z\), including the endpoints. A set \(C\) is convex if it contains this entire segment for every pair \(u,v\in C\).
The dot product and projection lesson uses a real parameter to move along a whole line. Restricting the parameter in \(u+t(v-u)\) to the unit interval gives the segment here.
Compare two heights at one input
A straight graph with two marked endpoints. The graph and its chord share the same height at the selected input.
The graph uses the mixed input. The chord mixes the two endpoint heights. For this affine function, the heights agree at every weight.
Exact definition
Let \(C\subseteq\mathbb R^n\) be convex and let \(f:C\to\mathbb R\). For every \(u,v\in C\) and \(t\in[0,1]\), compare the graph height at \(z=(1-t)u+tv\) with the chord height. The function \(f\) is convex when
\[ f(z)\le (1-t)f(u)+tf(v). \]It is strictly convex if the inequality is strict whenever \(u\ne v\) and \(0\lt t\lt 1\). An affine function on the real line has the form \(f(x)=ax+b\) for constants \(a,b\). Its chord heights agree with the graph heights, so it is convex but not strictly convex.
Refresher: coordinates, graph height, and boundary points
Multiply a vector by a scalar by multiplying every coordinate. Add vectors by adding the corresponding coordinates. A function assigns an output to each input in its domain. On the graph of a one-variable function, the point at input \(x\) has vertical coordinate \(f(x)\).
The inequality \(y\le b\) includes the boundary \(y=b\). A point must satisfy every listed inequality to belong to a region cut out by those inequalities. In the game, a solid boundary is included.
The chord test concerns the full domain. For a disconnected domain such as two separated intervals, a mixture of inputs can land in the gap. Under the convention here, check that the domain is convex before asking whether its function is convex.
Classify each region or graph
- Inspect the whole shaded region or the function on the drawn interval.
- Choose Convex or Nonconvex to see the reasoning and a segment or chord.
- Advance to the next case. Start over clears the current answer and score.
Move along a chord
- Commit to a prediction about the gap.
- After the reveal, move the weight with the slider or its number box to meet both goals.
The chord explorer opens after you check your prediction.
Keep the endpoints fixed. Increase \(t\) to give the right endpoint more weight. The vertical mark joins the graph and chord at the same input. Its length is their height difference for this square function.
Why the gap depends on the distance between endpoints
For \(f(x)=x^2\), the chord gap at \(z=(1-t)u+tv\) simplifies to
\[\begin{aligned} (1-t)u^2+tv^2-z^2 &=t(1-t)(v-u)^2. \end{aligned}\]Expand the square of \(z\) to obtain the identity. The gap is positive for distinct endpoints and an interior weight. It is zero at either endpoint or when the inputs coincide. For a fixed interior weight, doubling the distance between the inputs makes the gap four times as large. The resulting heights still depend on where the endpoints lie.
Turn the chord test into a set test
Let \(n\) be a positive integer, \(C\subseteq\mathbb R^n\) a nonempty convex set, and \(f:C\to\mathbb R\) a real-valued function. Its epigraph is the set above the graph, including the graph itself:
\[ E=\{(x,r): x\in C,\ r\ge f(x)\}. \]Then \(f\) is convex exactly when \(E\) is convex.
Build both directions. Fix any \(u,v\in C\), possibly equal, and any weight \(0\le t\le1\). Let \(z=(1-t)u+tv\). In the first direction, take real heights \(a\ge f(u)\), \(b\ge f(v)\), and put \(r=(1-t)a+tb\). In the reverse direction, use the two points on the graph.
Why the epigraph includes the graph
Take \(f(x)=|x|\) on the real line. A chord between graph points can rise above the graph. The graph by itself can fail the segment test even when the function is convex. The epigraph includes the space where such a chord can go. The reverse proof uses graph points as endpoints because that choice gives the smallest available heights at the two inputs.
For a fixed ceiling \(k\), the set of inputs with \(f(x)\le k\) is called a sublevel set. If \(f\) is convex on \(C\), this set is convex: each endpoint height is at most \(k\), so their weighted average is at most \(k\), and the graph at the mixed input is at most that average. In a design problem, if the cost is a convex function of the design variables, mixing two designs that each cost at most \(k\) gives a design that also costs at most \(k\).
A shortcut for smooth functions of one variable
Let \(I\) be an open interval and let \(f\) be twice differentiable on \(I\). Then \(f\) is convex on \(I\) exactly when \(f''(x)\ge 0\) for every \(x\in I\). If \(f''(x)\gt 0\) for every \(x\in I\), then \(f\) is strictly convex on \(I\).
The strict version runs one way only: \(f(x)=x^4\) is strictly convex on the real line, yet \(f''(0)=0\). The test also needs both of its hypotheses. The function \(f(x)=|x|\) is convex but has no second derivative at \(0\), so the test says nothing about it; the chord inequality settles it instead. The function \(f(x)=1/x^2\) has \(f''(x)=6/x^4\gt 0\) at every \(x\ne 0\), but its domain, the real line without \(0\), is not an interval, so under the convention here it is not a convex function.
The test agrees with the examples on this page. For \(f(x)=x^2\), \(f''(x)=2\gt 0\). For \(f(x)=3-x^2\), \(f''(x)=-2\lt 0\), so it is convex on no open interval. For \(f(x)=x^3\), \(f''(x)=6x\lt 0\) for \(x\lt 0\), which matches the chord below the graph in Apply.
Use the tests on new examples
Enter one number for each problem. Start with the endpoints and the weight, then decide whether the problem compares coordinates, graph heights, or both. Each problem has hints and a worked solution.
Related lessons: critical points studies the local behavior of a smooth surface near a stationary point. Jensen’s inequality extends the chord comparison to expectations.
Further reading
- S. Boyd and L. Vandenberghe, Convex Optimization, chapters 2, “Convex sets,” and 3, “Convex functions.”