Here’s an example of a Consumer Utility Maximization problem and its $Python$ implementation.
Problem Statement
A consumer has a utility function:
$$
U(x, y) = x^{0.5} \cdot y^{0.5}
$$
where $(x)$ and $(y)$ are the quantities of two goods consumed.
The consumer has a budget $(B = 100)$, and the prices of the goods are $(p_x = 2)$ and $(p_y = 5)$.
Objective:
Maximize $U(x, y)$ subject to the budget constraint:
$$
2x + 5y \leq 100
$$
Python Code Implementation
Here, we will solve the problem using SciPy‘s optimization tools and visualize the result.
1 | import numpy as np |
Explanation
Utility Function:
The function $U(x, y) = x^{0.5} \cdot y^{0.5}$ is modeled as negative because optimization functions typically minimize objectives.Budget Constraint:
$(2x + 5y \leq 100)$ is converted into a function forscipy.optimize.minimize.Optimization:
Theminimizefunction fromSciPysolves for $(x)$ and $(y)$ that maximize utility within the budget.Visualization:
The budget constraint and indifference curves (utility levels) are plotted.
The optimal point is marked for clarity.
Result Graph
Optimal consumption of good x: 24.99849398099728 Optimal consumption of good y: 10.000602407600788 Maximum utility: 15.8113882721523

The graph shows:
- The budget constraint as a line.
- Indifference curves for different utility levels.
- The optimal consumption bundle at the intersection of the budget constraint and the highest achievable indifference curve.








