Linear Programming Solver (2 variables)
Enter a linear objective z in x and y, choose maximise or minimise, and list the constraints (each row like x + 2y ≤ 14, separated by semicolons). The calculator finds every pairwise intersection of the boundary lines, keeps those that satisfy all constraints, evaluates z at each, and plots the feasible region with the optimum marked.
Corners, because the interior cannot win
Linear programming asks for the best value of a linear quantity subject to linear constraints — the most profit, the least cost, under limits on what is available. With two variables the whole problem can be drawn: each constraint is a half-plane, their overlap is the set of allowed choices, and the answer is one of its corners.
This solver works that way. It reads the objective and the constraints, finds every corner of the feasible region, evaluates the objective at each, and reports the best along with a plot of the region.
A linear objective has no peak in the middle of anything. It increases steadily in one direction across the whole plane, so from any interior point you can always move further and do better — until a constraint stops you. The optimum is therefore pushed to the boundary, and then along it to a corner.
That is why enumerating corners is a complete method rather than a shortcut. Every vertex is listed with its objective value, so the answer comes with the comparison that justifies it rather than as an assertion.
How to use this calculator
- Enter the objective in x and y A linear expression such as 5x + 4y. A constant term is accepted and shifts every value equally, so it never changes which corner wins.
- Choose maximise or minimise The same corners are found either way; only the comparison between their objective values changes.
- List the constraints, separated by semicolons Each in the form of a linear expression, a relation, and a number. At least two are required, and the non-negativity conditions count towards that.
- Read the corner list before the optimum Every feasible vertex is reported with its objective value. The optimum is simply the best entry in that list, and seeing the runners-up shows how much the choice matters.
How the optimum is found
Each constraint is parsed into a linear form and treated as a boundary line. Every pair of those lines is then intersected, which produces a candidate list containing every possible corner of the region along with many points that lie outside it.
Each candidate is tested against the full set of constraints, and only those satisfying all of them are kept. That single filter is what turns a list of arbitrary line crossings into the vertices of the feasible region, and duplicates arising from three lines meeting at one point are removed as they are found.
The objective is then evaluated at every surviving vertex and the best value selected according to the chosen direction. No search or iteration is involved: the answer is the extreme entry of a finite list.
For the plot, the vertices are sorted by angle around their own centroid so they form a simple polygon rather than a self-crossing outline, and each constraint line is drawn clipped to the plot box. If no candidate survives the filter the region is empty and the solver reports that rather than returning a point that violates a constraint.
What each input means
- z Objective — form field “Objective z (in x and y)”
- The linear quantity to optimise, written in x and y. Its coefficients set the direction of improvement across the plane.
- mode Direction — form field “Optimise”
- Maximise or minimise. It changes only which end of the list of corner values is chosen.
- constraints Constraints — form field “Constraints (semicolon-separated)”
- Semicolon-separated linear conditions. Each defines a boundary line and a permitted side of it.
Worked examples
Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.
A bounded maximisation
Maximise 5x + 4y under a mix of upper and lower bounds together with non-negativity. Five constraints give a closed polygon with several corners to compare.
Inputs Objective z (in x and y) = 5x + 4y, Optimise = max, Constraints (semicolon-separated) = x + 2y <= 14; 3x - y >= 0; x - y <= 2; x >= 0; y >= 0
- Objective max z = 5x + 4y
- Constraints x + 2y <= 14; 3x - y >= 0; x - y <= 2; x >= 0; y >= 0
- Method Find intersections of every pair of boundary lines, keep the feasible ones, evaluate z at each vertex.
- Feasible vertices V1 = (2, 6), z = 34; V2 = (6, 4), z = 46; V3 = (0, 0), z = 0; V4 = (2, 0), z = 10
- Optimum (max) (6, 4), z = 46
Result max z = 46 at (6, 4)
Five constraints give ten pairwise intersections, but only a few survive the feasibility test. The rest are genuine crossings of boundary lines that happen to lie outside the region — which is why the filter, not the intersection step, is what defines the polygon.
The winning corner is where two constraints are simultaneously tight. That is the general pattern: at an optimum in two variables, two constraints are active at once, and reading which ones tells you what is actually limiting the objective.
A minimisation with lower bounds
Minimise 2x + 3y subject to two greater-than constraints and non-negativity. The region is unbounded above, but the minimum still sits at a corner.
Inputs Objective z (in x and y) = 2x + 3y, Optimise = min, Constraints (semicolon-separated) = x + y >= 5; 2x + y >= 6; x >= 0; y >= 0
- Objective min z = 2x + 3y
- Constraints x + y >= 5; 2x + y >= 6; x >= 0; y >= 0
- Method Find intersections of every pair of boundary lines, keep the feasible ones, evaluate z at each vertex.
- Feasible vertices V1 = (1, 4), z = 14; V2 = (5, 0), z = 10; V3 = (0, 6), z = 18
- Optimum (min) (5, 0), z = 10
Result min z = 10 at (5, 0)
Nothing bounds the region from above, and nothing needs to: minimising pushes towards the origin, and the constraints block that direction. An unbounded region only causes trouble when the objective improves in the direction it opens.
Swapping this to maximise would have no answer at all, since the objective could grow forever. The solver would still report corners, so the direction has to be chosen with the shape of the region in mind.
Reading the result
Which constraints are binding
At the optimum, two constraints hold with equality and the rest have slack. Those two are the real limits on the objective, and relaxing either would improve it — which is usually the practical question behind the calculation.
Ties between corners
When the objective's direction is parallel to a boundary, both ends of that edge give the same value and so does every point between them. The solver reports one of them; the whole edge is equally optimal.
An empty region means inconsistent constraints
If no vertex satisfies everything, the constraints contradict each other and no allowed choice exists. That is a statement about the problem as posed, not a failure of the search.
When you would use this
Allocating limited resources
Two products competing for shared machine time, materials and labour is the classic setting: each resource is one constraint, and the objective is the profit from the mix.
Meeting requirements at least cost
Blending two inputs to satisfy minimum nutritional or chemical requirements is the same problem inverted — greater-than constraints and a minimised cost.
Assumptions and limitations
What this calculator assumes
- Exactly two variables, named x and y.
- The objective and every constraint are linear.
- At least two constraints are supplied, counting any non-negativity conditions.
- The optimum lies at a vertex, which the linearity of the objective guarantees on a region with corners.
Where it stops being the right tool
- Two variables only. Three or more require the simplex method, which cannot be drawn this way.
- Only non-strict relations and equality are meaningful; an optimum lies on the boundary, so a strict inequality would exclude the answer.
- An unbounded region in the direction the objective improves has no finite optimum, and the reported corner would not be one.
- No sensitivity analysis: shadow prices and the ranges over which the solution stays optimal are not computed.
- Integer requirements are not enforced, so a corner with fractional coordinates is reported as it stands.
Common mistakes
Omitting the non-negativity constraints
Why it happens. That quantities cannot be negative is so obvious it goes without saying — but the solver only knows the constraints it is given, and without them the region extends into quadrants that make no sense.
How to avoid it. State them explicitly as two more constraints. They are boundary lines like any other, and they frequently supply corners of the answer.
Reading the optimum from the plot
Why it happens. The picture makes the winning corner obvious, and its coordinates look easy to read off. The drawing is scaled for legibility, not for measurement.
How to avoid it. Take the coordinates from the corner list. They come from solving two linear equations exactly, not from the plot.
Maximising over a region that opens in the improving direction
Why it happens. The region looks like a legitimate feasible set and corners are still reported, so nothing signals that the true optimum is unbounded.
How to avoid it. Check that the constraints bound the region in the direction the objective grows. A maximisation needs upper limits, just as a minimisation needs lower ones.
Frequently asked questions
Why does the optimum always sit at a corner?
Because a linear objective has no interior extremum — it improves steadily in one direction, so from any interior point you can always move further. The improvement stops only at the boundary, and along the boundary only at a vertex.
What if the feasible region is empty?
The solver reports that no vertex satisfies every constraint. That means the constraints are mutually inconsistent, and the problem as posed has no allowed choice at all rather than merely a hard one.
What relations are supported?
Less-than-or-equal, greater-than-or-equal and equality. Strict inequalities are not used, because the optimum lies on the boundary and a strict relation would exclude exactly the point being looked for.
Can it handle more than two variables?
No. The graphical method depends on the feasible region being drawable in the plane. Three or more variables need the simplex algorithm, which walks between vertices algebraically instead.