Smallest circle covering points: a convex optimization example, solved and checked
The smallest circle covering points is a classic convex optimization problem. Here it is solved by a real solver (CLARABEL) and checked: every constraint, and the optimality certificate. Change the numbers below and solve your own.
Solve your own version free, no account needed
The problem
Find the smallest circle that contains the points (0, 0), (4, 0) and (0, 3).
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- (cx, cy) is the centre and r the radius. cx2 + cy2 ≤ r2 says the point (0, 0) is within r of the centre (Pythagoras, squared); the other two lines do the same for (4, 0) and (0, 3).
- For a right triangle the smallest circle has the longest side as its diameter: centre (2, 1.5), radius 2.5. The solver's centre agrees to its tolerance.
The model
Each line has a plain-language note on the right.
| make this as small as possible | |
| limit 1: left side cannot exceed the right side | |
| limit 2: left side cannot exceed the right side | |
| limit 3: left side cannot exceed the right side | |
| radius of the circle (length) cannot be negative |
What is being decided
There are 3 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| cx | real number | x-coordinate of circle center (length) |
| cy | real number | y-coordinate of circle center (length) |
| r | real number | radius of the circle (length) |
Goal and limits
Minimize the objective subject to 4 constraints, of which 1 are simple bounds on a single variable.
Problem type
Conic (convex), complexity level 4: convex nonlinear functions such as log, exp, square roots or powers. Solved with CLARABEL at the Medium solver tier.
The answer at a glance
The optimal value of each decision, as the solver returned it.
Which constraints hold the answer in place
Binding (no slack left): (2) cy^2 + (cx - 4)^2 <= r^2; (3) cx^2 + (cy - 3)^2 <= r^2. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | cx^2 + cy^2 <= r^2 | 6.24886 | 6.25 | 0.00113687 | |
| 2 | cy^2 + (cx - 4)^2 <= r^2 | 6.25 | 6.25 | -1.05804e-08 | yes |
| 3 | cx^2 + (cy - 3)^2 <= r^2 | 6.25 | 6.25 | -8.93396e-08 | yes |
| 4 | r >= 0 | 2.5 | 0 | 2.5 |
Algebraic model (low level)
Decision variables, objective and every constraint written out; this is exactly what the solver receives.
Model code (cvxpy)
The same model in cvxpy, ready to run.
import cvxpy as cp
cx = cp.Variable(name='cx') # x-coordinate of circle center (length)
cy = cp.Variable(name='cy') # y-coordinate of circle center (length)
r = cp.Variable(name='r') # radius of the circle (length)
objective = cp.Minimize(r)
constraints = [
cx**2 + cy**2 <= r**2,
cy**2 + (cx - 4)**2 <= r**2,
cx**2 + (cy - 3)**2 <= r**2,
r >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('cx =', cx.value)
print('cy =', cy.value)
print('r =', r.value)Solve your own
This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).
minimize r
subject to
cx^2 + cy^2 <= r^2
(cx - 4)^2 + cy^2 <= r^2
cx^2 + (cy - 3)^2 <= r^2
r >= 0
# cx = x-coordinate of circle center (length)
# cy = y-coordinate of circle center (length)
# r = radius of the circle (length)Checked: the app's answer matches the reference answer in our test set, which two solvers (CLARABEL, SCS) agree on. Built 2026-11-10.
Related examples
Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.