Back to the on-screen lesson ·
The chord, tangent and second-derivative tests, and the operations that let a convex objective be assembled.
Paper packet. Every task here also exists on screen, where it is checked automatically; answers written on paper are not assessed by Nydus. When you are back at a device, enter your answers there.
By the end of this lesson you will be able to state the chord definition of a convex function, apply the second-derivative test correctly over a whole domain rather than at one point, and recognise the standard convex functions on sight. You will also be able to build a convex objective out of pieces using the operations that preserve convexity — non-negative sums, maxima, and composition with an affine map — and to say which operations do not, so that a claim of convexity is something you can justify rather than hope for.
From the last lesson: a set is convex when every mixture of two of its points stays inside. You also know the second derivative test from calculus, where it told you whether a stationary point was a maximum or a minimum. Here it is doing something larger: not classifying one point, but certifying a statement about the whole function.
Convex function: one whose graph never rises above any of its chords.
Chord test: $f((1-\lambda)x + \lambda y) \le (1-\lambda)f(x) + \lambda f(y)$ — the definition, and the only test that survives a corner.
Tangent test: $f(y) \ge f(x) + f'(x)(y-x)$ — the graph lies above every tangent, so one point gives a bound everywhere.
Second-derivative test: $f'' \ge 0$ throughout the domain. The quickest, and the one that needs the most.
Concave: the negative of a convex function. Maximising a concave function is the same easy problem as minimising a convex one.
Strictly convex: the chord inequality is strict between the endpoints, which makes the minimiser unique.
Epigraph: the set of points on or above the graph. A function is convex exactly when this set is.
A function $f$ on a convex domain is convex when, for all $x, y$ in the domain and all $\lambda \in [0,1]$,
$$f(\lambda x + (1-\lambda)y) \;\le\; \lambda f(x) + (1-\lambda) f(y).$$
In words: the function at a mixture is at most the mixture of the values. Geometrically, the chord lies above the graph.
Three equivalent tests, in increasing order of convenience and decreasing order of generality:
| Test | Statement | Needs |
|---|---|---|
| Chord | $f(\lambda x + (1-\lambda)y) \le \lambda f(x) + (1-\lambda)f(y)$ | nothing |
| Tangent | $f(y) \ge f(x) + f'(x)(y - x)$ | one derivative |
| Second derivative | $f''(x) \ge 0$ throughout | two derivatives |
The chord test is the definition and works for functions with kinks — $|x|$ is convex and not differentiable at $0$. The tangent test says the graph lies above every tangent line, which is the form used in most proofs. The second-derivative test is the one to reach for in practice.
Concave is the mirror: $-f$ convex. Maximising a concave function is the same kind of easy problem as minimising a convex one, and minimising a concave function is as hard as anything in this course.
Operations that preserve convexity. These are worth memorising, because they are how a convex objective gets assembled:
Another way: picture
A bowl-shaped curve with a straight line drawn between two points on it. The line — the chord — is above the curve for the whole stretch between them. Now draw a tangent anywhere: the curve is above it everywhere. Those two pictures are the two tests, and a function that passes one passes the other.
Another way: steps
To decide whether a function is convex:
Suppose $f'' \ge 0$ everywhere. Then $f'$ is non-decreasing. Fix $x < y$ and let $z = \lambda x + (1-\lambda)y$ be between them.
By the mean value theorem there is a point $c_1$ in $(x, z)$ with $f(z) - f(x) = f'(c_1)(z - x)$, and a point $c_2$ in $(z, y)$ with $f(y) - f(z) = f'(c_2)(y - z)$. Since $c_1 < c_2$ and $f'$ is non-decreasing, $f'(c_1) \le f'(c_2)$, so
$$\frac{f(z) - f(x)}{z - x} \le \frac{f(y) - f(z)}{y - z}.$$
The slope up to $z$ is at most the slope on from $z$. Rearranging that inequality is exactly the chord condition. The content is the one sentence: a convex function's slope never decreases, and every other description of convexity is a restatement of it.
Checking $f''$ at one point. Convexity is a statement about the whole domain. $x^3$ has $f''(1) = 6 > 0$ and is not convex, because $f''(-1) = -6$.
Forgetting the domain. $-\log x$ is convex on $x > 0$, and the question does not arise elsewhere. A function convex on part of its domain is not a convex function, but restricting the domain — if the model allows it — can make it one.
Assuming differentiability. $|x|$ and $\max(x, 0)$ are convex and have kinks. The chord test still applies; the second-derivative test simply does not reach them, and unit 3's gradient methods need adapting for them.
Mixing up concave and convex. "Concave" is the one that holds water. Maximising concave is the easy direction; minimising concave is not, and a model that quietly does the second is a model whose answers mean much less than it appears.
In calculus you found a stationary point and checked $f''$ there to classify it. That is a local statement and it is all it claims to be: $f''(x^*) > 0$ says the point is a local minimum and says nothing about a better one somewhere else. Convexity is a statement about the whole domain, and it is what upgrades that local claim to a global one. The two get confused because they use the same derivative, and the difference is where the check is performed — at the answer, or everywhere. Every method in unit 3 that promises a global optimum is relying on the second kind of check having been done before the method ran.
$f(x) = 3x^2 - 4x + 1$: $f'' = 6 > 0$ everywhere, so convex. Its one stationary point is the global minimum.
Positive constant second derivative.
$f(x) = \log x$ on $x > 0$: $f' = 1/x$, $f'' = -1/x^2 < 0$ throughout. Concave, not convex — so maximising it is the easy direction and minimising it is unbounded below.
Negative throughout: concave.
$f(x) = x^3$: $f'' = 6x$, positive for $x > 0$ and negative for $x < 0$. Neither convex nor concave, and this is the usual case for a function picked at random. Convexity is a strong property and most functions do not have it.
Sign changes: neither.
A cost $c(x) = \max(2x, 5x - 30)$ — a rate that rises past a threshold. Each branch is affine, hence convex.
Start from pieces you recognise.
A maximum of convex functions is convex, so $c$ is convex despite its kink at $x = 10$. No differentiation was involved, and none is possible at the kink.
The operation does the work.
Now add a convex penalty $(x - 40)^2$ with a positive weight. A non-negative sum of convex functions is convex, so the total is convex — and a method that finds a local minimum of it has found the minimum. Reading this off the construction takes seconds; verifying it from the definition would take a page.
Which is why the operations are worth knowing.
Take the two terms separately. $e^{-x}$ is a composition of $e^u$, which is convex, with the affine map $u = -x$ — and composition with an affine map preserves convexity.
Use the operations before reaching for calculus.
$x^4$ has $f'' = 12x^2 \ge 0$ everywhere, so it is convex. (It is zero at the origin, which is allowed: the test asks for non-negative, not positive.)
A sum of convex functions with weights $1$ and $1$ is convex, so yes. Checking directly would mean differentiating the sum twice and arguing that $e^{-x} + 12x^2 \ge 0$ — true, and much more work than reading it off the construction.
Three tests decide convexity. Match each to the job it is the right tool for.
| The definition; the only one that still applies where the function has a corner | Turns one point into a lower bound valid everywhere — a certificate | The quickest check, once the function is known to be twice differentiable | |
|---|---|---|---|
| Chord test: $f((1-\lambda)x + \lambda y) \le (1-\lambda)f(x) + \lambda f(y)$ | |||
| Tangent test: $f(y) \ge f(x) + f'(x)(y - x)$ | |||
| Second-derivative test: $f''(x) \ge 0$ throughout the domain |
Is $x^3$ convex on all of $\mathbb{R}$?
What is the second derivative of $2x^2 + -8x + 11$?
Answer:
For $f(x) = x^2$, take the points $4$ and $8$ and their midpoint. Fill in the two heights the chord test compares.
| in symbols | height | |
|---|---|---|
| The function at the midpoint | ((4 + 8)/2)^2 | |
| The chord at the midpoint | (4^2 + 8^2)/2 |
For which values of $a$ is $a x^2 + -8x + 11$ convex on the whole line? Give the set.
This task has no paper form; do it on a device.
$f$ and $g$ are convex. Which of these is guaranteed convex?
Lesson test: one question per skill, one attempt each, no hints. Your answers are checked when you submit.
What is the second derivative of $5x^2 + -20x + 26$?
Answer:
You can test a function for convexity three ways, say which test applies when there is a kink, and assemble a convex objective from convex pieces. Next: the theorem all of this was for.
10. Your turn: is $f(x) = e^{-x} + x^4$ convex on $\mathbb{R}$?, step 3