fork download
  1. import numpy as np
  2. from scipy.optimize import minimize_scalar
  3.  
  4. # Define profit function
  5. def profit(p):
  6. return p * (2/(3*p)) - 0.1 * (2/(3*p))
  7.  
  8. # Find the maximum of the profit function using the bisection method
  9. result = minimize_scalar(lambda p: -profit(p), bounds=(0.01, 10), method='bounded')
  10.  
  11. # Optimal price p*
  12. optimal_price = result.x
  13.  
  14. # Quantity x* at the optimal price
  15. x_star = 2 / (3 * optimal_price)
  16.  
  17. # Calculate revenue and cost at the optimal price
  18. revenue = optimal_price * x_star
  19. cost = 0.1 * x_star
  20.  
  21. # Calculate net utility received by the EU and money received by the ISP
  22. net_utility = 0.4 * revenue
  23. money_received_ISP = 0.6 * revenue
  24.  
  25. # Print the results
  26. print("Price that maximizes profit (p*):", optimal_price)
  27. print("Quantity created and delivered (x*):", x_star)
  28. print("Maximum profit of the CP:", -result.fun) # Minimization result is negative of profit
  29. print("Net utility received by the EU:", net_utility)
  30. print("Money received by the ISP:", money_received_ISP)
  31.  
Success #stdin #stdout 0.32s 44008KB
stdin
Standard input is empty
stdout
Price that maximizes profit (p*): 9.999996482655359
Quantity created and delivered (x*): 0.0666666901156392
Maximum profit of the CP: 0.6599999976551029
Net utility received by the EU: 0.2666666666666667
Money received by the ISP: 0.4