1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Optimization in Python

Connected

Exercise

Utility maximization

Bill is an aspiring piano student who allocates hours of study in classical \(c\) and modern \(m\) music. His preferences are represented by the same utility function you just plotted:

\(U(c, m)=c^{0.7}m^{0.3}\).

Hours of study sum up to 2 (\(c+m=2\)) daily. Help Bill find the optimal studying plan.

np and minimize have been loaded for you. We have already imported symbols, diff and solve from SymPy, defined c and m as symbols and defined the Utility function U for you.

Instructions

100 XP
  • Define the utility function by unpacking vars and returning the negated function.
  • Define the constraint function.
  • Set up the constraint with type and fun.
  • Perform optimization and extract the results for c and m.