Simplex Method Calculator

Solve a linear programming problem step by step. Every tableau, entering and leaving variable, ratio test and row operation is shown and explained, in exact fractions. ≥ and = constraints are handled with the Big M or the Two-Phase method. At the optimum you also get a sensitivity analysis (shadow prices, reduced costs, ranges) and the dual problem.

  • Exact fractions, no rounding
  • Big M and Two-Phase
  • Graph for 2 variables

Linear program

Objective function
max z =x1+x2
Subject to
C1x1+x2
C2x1+x2
C3x1+x2

All variables are nonnegative: x1, x2 ≥ 0

Method for ≥ and = constraints

Only used when the problem has ≥ or = constraints. Problems with only ≤ constraints are solved with the plain simplex method.

Type integers, decimals or fractions (3, -2.5, 3/4). Empty boxes count as 0.

Result

Optimal solution found
Optimal valuez* = 23
Optimal solution
x1 = 3x2 = 2
Method
Simplex
Iterations
2

Constraint check

ConstraintLeft sideRight sideStatus
C15≤5Binding
C28≤8Binding
C32≤4Slack 2

Step-by-step solution

Step 1 of 4
Step 1 of 4

Standard form

Each constraint is turned into an equation:

  • ≤ constraint: add a slack variable s.
max z = 5 x1 + 4 x2
C1x1 + x2 + s1 = 5
C22 x1 + x2 + s2 = 8
C3x2 + s3 = 4
x1, x2, s1, s2, s3 ≥ 0

The starting basis is s1, s2, s3.

s = slack, e = surplus, a = artificial. Row 0 is the objective written as z − c·x = 0, so its entries are Zj − Cj.

Step 1 of 4

Sensitivity analysis

How the optimal solution responds when one number of the problem changes and all the others stay the same. Shadow prices, reduced costs and ranges are computed exactly from the optimal basis.

Objective coefficients

While a coefficient stays within its range of optimality, the optimal solution x* does not change (only z* does). The reduced cost is the change in z per unit of a variable forced into the solution.

Objective coefficients
VariableOptimal valueReduced costCoefficientAllowable decreaseAllowable increaseRange of optimality
x1305134 ≤ c1 ≤ 8
x22043/215/2 ≤ c2 ≤ 5
Show the work

x1 is basic. When c1 changes by δ, the row-0 entry of every nonbasic variable changes by δ times its entry in the row of x1. Each must stay ≥ 0:

  • s1: 3 − δ ≥ 0 ⇒ δ ≤ 3
  • s2: 1 + δ ≥ 0 ⇒ δ ≥ −1

Range of optimality: 4 ≤ c1 ≤ 8.

x2 is basic. When c2 changes by δ, the row-0 entry of every nonbasic variable changes by δ times its entry in the row of x2. Each must stay ≥ 0:

  • s1: 3 + 2δ ≥ 0 ⇒ δ ≥ −3/2
  • s2: 1 − δ ≥ 0 ⇒ δ ≤ 1

Range of optimality: 5/2 ≤ c2 ≤ 5.

Constraints and shadow prices

The shadow price is the change in z* per unit increase of the right-hand side. It holds while the right-hand side stays within its range of feasibility; outside it the optimal basis changes.

Constraints and shadow prices
ConstraintFinal valueSlack or surplusShadow priceRight-hand sideAllowable decreaseAllowable increaseRange of feasibility
C1 (≤)5Binding35114 ≤ b1 ≤ 6
C2 (≤)8Binding18226 ≤ b2 ≤ 10
C3 (≤)22042∞b3 ≥ 2
Show the work

Optimal basis (rows of the final tableau): x2, x1, s3, with cB = (4, 5, 0).

B⁻¹: one row per basic variable, one column per constraint.

C1C2C3
x22−10
x1−110
s3−211

Shadow prices: y = cB·B⁻¹ = (3, 1, 0).

When b1 changes by Δ, the basic variables change by Δ times the column of B⁻¹ for C1, which is the s1 column of the final tableau. Each must stay ≥ 0:

  • x2: 2 + 2Δ ≥ 0 ⇒ Δ ≥ −1
  • x1: 3 − Δ ≥ 0 ⇒ Δ ≤ 3
  • s3: 2 − 2Δ ≥ 0 ⇒ Δ ≤ 1

Range of feasibility: 4 ≤ b1 ≤ 6. In this range z* changes by 3 per unit of b1.

y1 is the row-0 entry under s1 in the final tableau.

When b2 changes by Δ, the basic variables change by Δ times the column of B⁻¹ for C2, which is the s2 column of the final tableau. Each must stay ≥ 0:

  • x2: 2 − Δ ≥ 0 ⇒ Δ ≤ 2
  • x1: 3 + Δ ≥ 0 ⇒ Δ ≥ −3
  • s3: 2 + Δ ≥ 0 ⇒ Δ ≥ −2

Range of feasibility: 6 ≤ b2 ≤ 10. In this range z* changes by 1 per unit of b2.

y2 is the row-0 entry under s2 in the final tableau.

When b3 changes by Δ, the basic variables change by Δ times the column of B⁻¹ for C3, which is the s3 column of the final tableau. Each must stay ≥ 0:

  • s3: 2 + Δ ≥ 0 ⇒ Δ ≥ −2

Range of feasibility: b3 ≥ 2. In this range z* changes by 0 per unit of b3.

y3 is the row-0 entry under s3 in the final tableau.

The dual problem

Every linear program has a dual problem with one variable per constraint. Its optimal solution is exactly the shadow prices, and both problems have the same optimal value (strong duality).

Minimize w = 5y1 + 8y2 + 4y3

Subject to

y1 + 2y2 ≥ 5

y1 + y2 + y3 ≥ 4

y1, y2, y3 ≥ 0

Rules for a maximization problem: a ≤ constraint gives y ≥ 0, a ≥ constraint gives y ≤ 0 and an = constraint gives a free y (any sign). Each variable x ≥ 0 gives a ≥ constraint of the dual.

Optimal dual solution
y1 = 3y2 = 1y3 = 0

w* = 23 = z*: the dual optimum equals the primal optimum (strong duality).

Complementary slackness

  • C3 has slack 2 > 0, so y3 = 0.
  • x1 > 0, so dual constraint 1 holds with equality.
  • x2 > 0, so dual constraint 2 holds with equality.
Solve the dual step by step

Opens in a new tab, where the dual variables y₁, y₂, … are shown as x₁, x₂, ….

How the simplex method works

What is the simplex method?

The simplex method, published by George Dantzig in 1947, is the classic algorithm for linear programming: maximizing or minimizing a linear objective subject to linear constraints. The feasible solutions form a convex polygon (a polytope in higher dimensions), and when an optimal solution exists, one is always found at a corner point. The simplex method starts at a corner and moves along an edge to an adjacent corner that improves the objective, until no neighbouring corner is better.

How to read a simplex tableau

Each row of the tableau is one constraint written as an equation. The first column names the basic variable of the row, and its value is in the RHS column; every nonbasic variable is 0. Row 0 is the objective written as z − c₁x₁ − … − cₙxₙ = 0, so its entries are the Zj − Cj values and its right-hand side is the current value of z. In a maximization problem, a negative entry in row 0 means that increasing that variable increases z.

One iteration: entering variable, ratio test and pivot

In a maximization problem the entering variable has the most negative coefficient in row 0 (in a minimization problem, the most positive). The minimum ratio test divides each right-hand side by the positive entry of the entering column: the row with the smallest ratio is the first constraint to become tight, so its basic variable leaves. Row operations then turn the entering column into a unit column, which gives the next tableau.

Slack, surplus and artificial variables

A ≤ constraint becomes an equation by adding a slack variable (s), the unused capacity. A ≥ constraint subtracts a surplus variable (e) and, because −e cannot start in the basis, also adds an artificial variable (a). An = constraint gets an artificial variable only. Artificial variables mean nothing in the original problem: they must reach zero before the solution is valid.

Big M or Two-Phase?

Both methods remove the artificial variables. Big M puts them in the objective with a huge penalty M, so the simplex method pushes them out while it optimizes. This calculator keeps M as a symbol, so tableaus show entries such as 3M − 2 exactly instead of a rounded large number.

The Two-Phase method first minimizes r, the sum of the artificial variables (Phase I). If the minimum is 0, it drops the artificial columns and optimizes the real objective from that feasible basis (Phase II); if the minimum is positive, the problem is infeasible. Both methods reach the same optimal value.

Special cases

Degeneracy: a basic variable equals 0, and a pivot may leave the objective unchanged. In rare cases the method can cycle; this calculator detects a repeated basis and switches to Bland’s rule, which always terminates.

Unbounded problem: the entering column has no positive entry, so the objective can improve forever. Infeasible problem: an artificial variable stays positive at the end. Alternative optima: a nonbasic variable has 0 in row 0 of the optimal tableau, so another optimal corner exists.

Sensitivity analysis and duality

After the optimal tableau, the calculator runs a sensitivity analysis. The shadow price of a constraint is how much the optimal value z* changes per unit increase of its right-hand side; the reduced cost of a variable is how much z changes per unit of that variable forced into the solution. The ranges tell you how far one coefficient or right-hand side can move, all others fixed, before the optimal basis changes.

Every linear program also has a dual problem, with one variable per constraint. Its optimal solution is exactly the vector of shadow prices, and by strong duality both problems have the same optimal value. Complementary slackness links the two: a constraint with slack has a shadow price of 0, and a positive variable makes its dual constraint tight.

Frequently asked questions

Can the calculator solve minimization problems?

Yes. Choose Minimize. The entering variable is then the one with the most positive coefficient in row 0, and the tableau is optimal when no coefficient in row 0 is positive.

Why are the numbers shown as fractions?

The calculator uses exact rational arithmetic, so every tableau matches what you get by hand and no rounding error can change a pivot. You can switch to decimals at any time; decimals are rounded to 4 places for display only.

What if a right-hand side is negative?

The simplex method needs nonnegative right-hand sides, so that constraint is first multiplied by −1 and its inequality is reversed (≤ becomes ≥). The step-by-step solution shows this conversion.

How large can the problem be?

Up to 8 variables and 8 constraints, which covers textbook and exam problems while keeping every tableau readable. All variables are assumed to be nonnegative.

Does it solve integer programming problems?

No. It solves the linear programming problem, so optimal values can be fractional. Integer programs need methods such as branch and bound, which solve a sequence of linear programs like this one.

What is a shadow price in linear programming?

The shadow price of a constraint is the change in the optimal objective value per unit increase of its right-hand side, as long as the change stays within the allowable range. A constraint with slack has a shadow price of 0. The calculator lists every shadow price with its range of feasibility and shows how each one is read from the final tableau.

Does the calculator find the dual problem?

Yes. Below the solution it writes the dual problem with the correct sign for each dual variable, gives its optimal solution (the shadow prices) and checks strong duality and complementary slackness. When every dual variable is nonnegative, you can open the dual in the calculator and solve it step by step.

Related on LearnGraphTheory