Utility maximization
Bill एक नया पियानो छात्र है जो रोज़ाना अपनी पढ़ाई का समय classical \(c\) और modern \(m\) संगीत के बीच बाँटता है। उसकी पसंद वही utility फंक्शन दर्शाता है जिसे आपने अभी प्लॉट किया था:
\(U(c, m)=c^{0.7}m^{0.3}\).
रोज़ाना पढ़ाई के घंटे कुल 2 होते हैं (\(c+m=2\))। Bill को optimal स्टडी प्लान ढूँढने में मदद करें।
np और minimize आपके लिए लोड कर दिए गए हैं। हमने पहले ही SymPy से symbols, diff और solve इम्पोर्ट कर लिए हैं, c और m को symbols के रूप में परिभाषित किया है, और Utility फंक्शन U भी परिभाषित है।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Optimization परिचय
अभ्यास निर्देश
varsको अनपैक करके utility फंक्शन परिभाषित करें और उसका negative रिटर्न करें।- constraint फंक्शन परिभाषित करें।
typeऔरfunके साथ constraint सेट करें।- optimization चलाएँ और
cऔरmके नतीजे निकालें।
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define the utility function
def utility_function(vars):
____
return ____
# Define the constraint function
def constraint(vars):
return ____
initial_guess = [12, 12]
# Set up the constraint
constraint_definition = {____}
# Perform optimization
result = ____
____ = result.____
print("Optimal study hours for classical music:", round(c, 2))
print("Optimal study hours for modern music:", round(m, 2))