problem 4X+3Y=9 2X-3Y=9
from pulp import *
#Mathematical model creation
prob = LpProblem(sense=LpMinimize)
#variable
x = LpVariable('x', cat='Continious')
y = LpVariable('y', cat='Continious')
#Definition of constraint expression(Problem part)
prob += 4* x + 3*y ==9
prob += 2* x - 3*y ==9
#Solution
status = prob.solve()
print(LpStatus[status])
print('x:%.if y:%if' % (value(x), value(y)))
Yes. I got the answer. If you use programming for simultaneous equations in junior high school mathematics, some people may not understand it at a cram school.
If you buy 22 apples for 120 yen each and mandarin oranges for 150 yen each. The total was 2711 yen. How many apples and oranges did you buy?
prob = LpProblem(sense=LpMinimize)
#variable
x = LpVariable('x', cat='Continious')
y = LpVariable('y', cat='Continious')
#Definition of constraint expression
prob += 120* x + 150*y ==2711
prob += x + y ==22
#Solution
status = prob.solve()
print(LpStatus[status])
print('x:%.if y:%if' % (value(x), value(y)))
Yes I got the answer. There are 19 apples and 2 oranges. It is convenient to be able to solve such annoying problems in an instant.
Recommended Posts