1.2.8 · D4Calculus & Optimization Basics

Exercises — Convex vs non-convex functions

3,013 words14 min readBack to topic

Before we start, three tools we lean on constantly. Each is stated in plain words so no symbol appears unearned.

For matrices we use one shortcut over and over, so let's earn it now.

Recall Why a diagonal matrix's eigenvalues are its diagonal entries

For , the quadratic form is . Feeding in the axis directions gives and gives : the surface curves by exactly along one axis and along the other — those are the two principal curvatures, i.e. the eigenvalues. Equivalently has roots . So for diagonal Hessians you can read convexity straight off the diagonal.


Level 1 — Recognition

Recall Solution L1.1

Each is on all of (a convex domain), so the everywhere rule applies.

  • (a) everywhere → convex (affine functions are convex and concave — the boundary case).
  • (b) everywhere → convex (equals only at ; still ).
  • (c) , which is positive on some intervals and negative on others → not convex.
  • (d) everywhere → convex. Convex: (a), (b), (d). Not: (c).
Recall Solution L1.2

The matrix is diagonal, so (by the boxed recall above) its diagonal entries and are its eigenvalues — the surface curves by along the first axis and by along the second. One eigenvalue is negative → the matrix is indefinitenot positive semidefinite → not convex at that point. The negative direction (-axis here) is a direction where the surface bends down.


Level 2 — Application

Recall Solution L2.1

, . Since for every real , everywhere → strictly convex ( is on all of , so the test is valid). Stationary points need , i.e. . But is never zero stationary points. A convex function can have no minimum if it keeps sloping down forever (here toward ).

Recall Solution L2.2

Second partials: , , . So Check the shortcut: , , . Positive definite → strictly convex everywhere.

Recall Solution L2.3

Blended input: .

  • Left (curve): .
  • Right (chord): . ✓. The curve sits below the chord, as convexity promises.

Level 3 — Analysis

Recall Solution L3.1

, .

  • convex on .
  • concave on . The sign of flips at : this is the inflection point. Because is not over the whole line, is not convex globally — it's a textbook non-convex shape.

The figure below draws exactly this. Look at the two thick coloured pieces of the curve: the plum left half () caves down like a frown — that's the concave region where . The teal right half () cups up like a smile — the convex region where . The orange dashed line marks , the single point where the curvature flips sign (the inflection). Notice the curve is perfectly smooth there — nothing dramatic happens to itself, only to its bending direction. That visual is why "convex" can never describe the whole cubic: no single bowl shape covers both halves.

Figure s01 — Convex vs concave regions of the cubic . The plum arc on is concave (, curving down like a frown); the teal arc on is convex (, cupping up like a smile); the orange dashed vertical at marks the inflection point where curvature flips sign. Axes: horizontal , vertical .

Figure — Convex vs non-convex functions
Recall Solution L3.2

(constant, so same everywhere). → eigenvalues have opposite signs → indefinite. Eigenvalues satisfy and , giving , i.e. and . One up-curving direction, one down-curving → saddle point, non-convex.

Recall Solution L3.3

, diagonal so eigenvalues are and . PSD requires both eigenvalues : ✓ always, and . Convex . For it's a flat "valley trough" (still convex, min not unique — a whole line of minima). For the second eigenvalue is negative → saddle.


Level 4 — Synthesis

Recall Solution L4.1

Proof via the chord test. Fix inputs and weight . Convexity of and gives Multiply the first by and the second by — inequalities survive multiplication by nonnegatives — then add: which is exactly . So is convex. Why the regularizer stays convex: has constant Hessian (PSD). Adding it to a convex data loss is a nonnegative combination (), so the total is convex. This is why ridge regression stays a nice single-bowl problem — see Convex Optimization.

Recall Solution L4.2

Step 1 — Taylor's theorem with exact (Lagrange) remainder. For a function, expanding around a base point and evaluating at gives, for some point strictly between and , Why this tool? Taylor's theorem is the one device that writes exactly — no approximation — while isolating the curvature into a single remainder term . That is precisely the term our hypothesis controls. Step 2 — Bound the remainder. Since (hypothesis) and (a square), the remainder is . Dropping a nonnegative term can only decrease the right side: This is the first-order (tangent) condition: the graph lies above every tangent line. Step 3 — Tangent condition chord test. Let . Apply the tangent inequality from Step 2 twice, based at : Weight by and and add. The slope terms combine into , and the bracket is , so it vanishes: That is the chord test — is convex. What it looks like: Taylor gives us "curve above tangent" from the sign of curvature; averaging two such tangent inequalities gives "curve below chord."


Level 5 — Mastery

Recall Solution L5.1

(a) Stationary points — set the gradient to zero. . . Stationary points: . (b) Hessian (diagonal → eigenvalues on the diagonal).

  • At : → eigenvalues → indefinite → saddle point.
  • At : → both positive → local min, value .
  • At : identical, local min, value . (c) Since the Hessian is indefinite at , is not convex. There are two equally-deep global minima at plus a saddle between them. Gradient descent starting with flows to ; starting with flows to . Same loss value here, but this is the mechanism by which non-convex losses split into basins — the outcome depends on initialization.

The figure below is the slice through , so we watch the -behaviour alone (where all the interesting non-convexity lives). Trace the black curve: it dips into a teal basin at , climbs up over an orange hump at the origin, then dips into a second plum basin at . Both basins bottom out at — equally deep global minima — while the orange point at the top () is the saddle. This is the visual proof of "two basins": a marble released on the left of the hump rolls to , one on the right rolls to . Which minimum you reach is decided purely by which side of the hump you start on — the essence of initialization-dependent optimization.

Figure s02 — Two basins plus a saddle for (slice at ). The black curve dips to a teal minimum at (value ), rises over an orange hump/saddle at (value ), then dips to a plum minimum at (value ). Two equally deep global minima separated by a hump — descent reaches one or the other depending on the sign of the starting . Axes: horizontal , vertical .

Figure — Convex vs non-convex functions
Recall Solution L5.2

Domain (a convex set) and is there. . . On , everywhereconvex on all of . Minimizer: . Value . Since is convex, this single stationary point is the global minimum.

Recall Solution L5.3

Compute the Hessian. Second partials: , , . So Apply the PSD shortcut: ✓, ✓, and Convex (with ). Beyond that, the cross term dominates, , and a downhill direction opens up.


Recall One-line self-quiz before you leave

For a Hessian , what three conditions guarantee convexity? ::: , , and (nonnegative diagonals and nonnegative determinant).

Connections