Consumer's best bundle (utility maximization): a convex optimization example, solved and checked
The consumer's best bundle (utility maximization) 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
A consumer with utility 0.3 ln x + 0.7 ln y has $100; good x costs $2 and good y costs $5. How much of each should she buy?
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- 2x + 5y ≤ 100: spending on x at $2 a unit and on y at $5 a unit is at most $100.
- Utility 0.3 ln x + 0.7 ln y: more of either good helps, but each extra unit helps a little less. The weights 0.3 and 0.7 say how much she cares about each good.
The model
Each line has a plain-language note on the right.
| make this as large as possible | |
| limit 1: left side cannot exceed 100 | |
| quantity of good x purchased (units) cannot be negative | |
| quantity of good y purchased (units) cannot be negative |
What is being decided
There are 2 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x | real number | quantity of good x purchased (units) |
| y | real number | quantity of good y purchased (units) |
Goal and limits
Maximize the objective subject to 3 constraints, of which 2 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.
Picture
Shaded: every point that satisfies all the constraints. Dot: the optimum. Dashed: the objective's level line through it.
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): (1) 2*x + 5*y <= 100. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | 2*x + 5*y <= 100 | 100 | 100 | 3.9533e-07 | yes |
| 2 | x >= 0 | 15.002 | 0 | 15.002 | |
| 3 | y >= 0 | 13.9992 | 0 | 13.9992 |
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
x = cp.Variable(name='x') # quantity of good x purchased (units)
y = cp.Variable(name='y') # quantity of good y purchased (units)
objective = cp.Maximize(0.3*cp.log(x) + 0.7*cp.log(y))
constraints = [
2*x + 5*y <= 100,
x >= 0,
y >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('x =', x.value)
print('y =', y.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).
maximize 0.3*log(x) + 0.7*log(y)
subject to
2*x + 5*y <= 100
x, y >= 0
# x = quantity of good x purchased (units)
# y = quantity of good y purchased (units)
# asked: the optimal quantities of x and y to buyChecked: 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.