# Plotting multiple equations in optimization problem

Working in finance field, I come across optimization (minimize cost maximize profit) problems which could be done on paper easily with two constraint variables and can even visualize solutions for three dimensional problems however I do not know anyway with which I could solve problems for over three variables or constraints except to do them on computer. Here is an example with two variables

Profitability = A table generates 40 dollars and chair gives 30 dollars Constraints: Material1: while a table consumes 7 units of material1 chair consumes units 4 of that. There are 200 units of that material available. Constraints: Material2: each Table and chair consumes 5 units of material2 of which 400 are available.

Syntax for this problem in Mathematica is as follows:

Maximize[{
40 tables + 30 chairs,
7 tables + 4 chairs <= 200 &&
5 tables + 5 chairs <= 400 &&
chairs ≥ 0 && tables ≥ 0},
{chairs, tables}]


And another similar problem (with four constraints) can be solved with following syntax:

Maximize[{
45000 P1 + 63000 P2 + 27500 P3 + 19500 P4 + 71000 P5 + 56000 P6 + 48500 P7,
6 P1 + 9 P2 + 4 P3 + 4 P4 + 7 P5 + 10 P6 + 6 P7 <= 800 &&
12 P1 + 16 P2 + 10 P3 + 5 P4 + 10 P5 + 5 P6 + 7 P7 <= 900 &&
0 P1 + 4 P2 + 4 P3 + 0 P4 + 8 P5 + 7 P6 + 10 P7 <= 700 &&
5 P1 + 8 P2 + 5 P3 + 7 P4 + 4 P5 + 0 P6 + 3 P7 <= 375 &&
25 >= P1 >= 0 && 30 >= P2 >= 0 && 47 >= P3 >= 0 && 53 >= P4 >= 0 &&
16 >= P5 >= 0 && 19 >= P6 >= 0 && 36 >= P7 >= 0},
{P1, P2, P3, P4, P5, P6, P7}]


How can I see these function/equations on graph? First one (with two variables) could be done on paper but I do not know how to plot even that in Mathematica.

Question was edited (the inequalities '<' and '>' were changed to '>=' and '=<' ) to get non boundary solution. But I don't understand what does boundary solution mean. Also, both answers are actually the same (in output) and could you tell me what are boundary and non boundary solutions (the one with errors) mean?

• Can't believe that I am so lucky to be part of this community. Must thank God and WolfRam and Mathematica team. – Jawad_Mansoor Feb 22 '17 at 15:48
• I'm voting to close this question as off-topic because it is soliciting private consultation through email. – Szabolcs Feb 22 '17 at 15:48
• @Szabolcs Ok don't close. I found a way to receive message in email automatically. Thank you however for contribution. – Jawad_Mansoor Feb 22 '17 at 16:00
• @Szabolcs by the way you mentioned that it was off topic. How was this off topic? The question related to Mathematica, syntax was requested for plotting multiple equations in a graph. Why and (if ever) how is it off topic? – Jawad_Mansoor Feb 22 '17 at 16:06
• You clearly stated that you will not be able to come back to read the answer and you want to receive them in email. That made it unambiguously off topic. Of course now you changed that—which is good. You can read about how this site works here and learn about what questions are considered appropriate from the first two sections here. – Szabolcs Feb 22 '17 at 16:59

Your problems are somewhat ill-posed, in that in some cases one constraint is strictly weaker than another, and so gets "swallowed up" by the first one and it doesn't have any effect on the final feasible region.

For example, in your first tables-chairs case, you could write:

Maximize[{
40 tables + 30 chairs,
7 tables + 4 chairs <= 200 &&
5 tables + 5 chairs <= 400 &&
chairs ≥ 0 && tables ≥ 0},
{chairs, tables}]

(* Out: {1500, {chairs -> 50, tables -> 0}} *)


which returns a definite answer, albeit an uninteresting one. In fact, you can see that the feasible region is not impacted by one of your inequalities:

RegionPlot[
{7 tables + 4 chairs <= 200, 5 tables + 5 chairs <= 400},
{chairs, 0, 100}, {tables, 0, 100},
FrameLabel -> {"chairs", "tables"}
]


Here is a slightly more complex 2D problem (from Purplemath):

A company produces a scientific and a graphing calculator. Projections indicate a demand of at least 100 scientific and 80 graphing calculators each day, but no more than 200 scientific and 170 graphing calculators can be made daily. A shipping contract also requires them to ship at least 200 calculators each day.

Each scientific calculator results in a \$2 loss, but each graphing calculator produces a \$5 profit. How many calculators of each type should be made daily to maximize profits?

In this case we can translate naively to:

constraints = {100 <= sci <= 200, 80 <= gra <= 170, sci + gra >= 200};
Maximize[{5 gra - 2 sci, constraints}, {gra, sci}]
(* Out: {650, {gra -> 170, sci -> 100}} *)


To explore the feasible region, let's use RegionPlot to draw the region indicated by each constraint:

RegionPlot[
Evaluate@constraints,
{sci, 0, 210}, {gra, 0, 180},
PlotStyle -> Directive[Black, Opacity[0.2]],
FrameLabel -> {"scientific", "graphic"}
]


Alternatively, we can combine all constraints (logical And) to find the feasible region:

RegionPlot[
And @@ constraints,
{sci, 0, 210}, {gra, 0, 180},
PlotPoints -> 60,
FrameLabel -> {"scientific", "graphic"}
]


• @macrob Thank you man, that was very helpful. How do I vote your reply up? – Jawad_Mansoor Feb 23 '17 at 8:07
• @Jawad Unfortunately your reputation count is still too low to vote up answers (see here), but if you thin my answer properly addresses your questions, you can accept it by clicking the gray check mark close to it so it turns green. – MarcoB Feb 23 '17 at 13:09
• @MacroB, Thank you. But I can't find any grayed button anywhere either. Anyway, I heard that linear programming command is much faster (as the problem is linear so it should be solved) however I don't know how to Maximize or Minimize a linear problem. Can you formulate it, what will be syntax if I use linear programming command (i.e. to maximize or minimize) – Jawad_Mansoor Feb 23 '17 at 20:09
• @Jawad I'd suggest that you try to work through the documentation for that: see LinearProgramming itself and, more in general, The linear programming tutorial. – MarcoB Feb 23 '17 at 21:12