[PYTHON] Solve multivariable optimization problems using sagemath

Computer algebra software such as Mathematica and sagemath can easily solve the problem. Here, the multivariable optimization problem is solved by taking the TV manufacturing problem as an example.

problem

The manufacturer is planning two types of products.

The manufacturer's suggested retail price for product A is $ 339, and the cost is $ 195 per unit. The manufacturer's suggested retail price for product B is $ 399, and the cost is $ 225 per unit.

It also costs a fixed cost of $ 400,000.

From the relationship between supply and demand, it is considered that the number of units sold affects the price. In both cases, it is estimated that the average selling price will drop by 1 cent for each additional unit sold. In addition, the average selling price of product A drops by 0.3 cents for each additional product B sold. For every one more product A sold, the average selling price of product B drops by 0.4 cents.

How much should you sell for maximum profit?

Install and run

# pacman -S sagemath
$ sage

┌─────────────────────────────────────────┐
│ SageMath version 7.6, Release Date: 2017-03-25                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└─────────────────────────────────────────┘
sage: 


Solution by sagemath

s:Sales volume of product A
t:Product B sales volume
p:Selling price of product A
q:Selling price of product B
C:cost
R:Revenue from product sales($/year)
P:Profit from product sales($/year)

sagemath.py


sage: var("s t")                                                  
sage: p = 339-0.01*s-0.003*t                                      
sage: q = 399-0.004*s-0.01*t                 
sage: R = p*s+q*t                                                 
sage: C = 400000+195*s+225*t                                        
sage: P(s,t)=R-C                                                  
sage: solve([diff(P,s)==0, diff(P,t)==0, s>=0, t>=0], s,t)
[[s == (554000/117), t == (824000/117)]]
sage: P(554000/117, 824000/117)
553641.025641025

Interpretation of solution

What is required by solve is that the profit P takes an extreme value. The values s and t obtained by this are the number of units sold that can obtain the maximum profit. By giving the values of s and t obtained here to the function P (s, t), the maximum profit can be obtained. In other words, if you sell about 4735 units of product A and about 7043 units of product B, you will get a maximum profit of $ 553641.

Recommended Posts

Solve multivariable optimization problems using sagemath
Solve optimization problems in Python
Try function optimization using Hyperopt
Notes on optimization using Pytorch
Try to solve the function minimization problem using particle swarm optimization