πŸ“˜ CodingMarble Learn

The Simplex Algorithm: Solving Linear Programs with Tableaux

The graphical method works for two variables, but real problems have many. The simplex algorithm solves them with a table (tableau). Add a slack variable to each ≀ constraint, start at the origin, and pivot: choose the most negative number in the objective row, use the ratio test to choose the row, and clear the column. Each pivot moves to a better corner of the feasible region. When the objective row has no negative numbers, the tableau is optimal and you read the answer. To minimise C, maximise βˆ’C.

🎬 Step-by-step story

  1. Here is a linear program: maximise P = 3x + 2y with three ≀ constraints. Green is the feasible region.
  2. Slack variables r, s and t fill each gap so every ≀ becomes =. At the origin, r = 4, s = 9, t = 3.
  3. Pivot 1: x has the most negative entry (βˆ’3). The ratio test picks the t row. The ball moves to (3, 0): P = 9.
  4. Pivot 2: y has βˆ’2. Ratios 1 and 2, so the r row. The ball moves to (3, 1): P = 11.
  5. No negatives in the P row: optimal. Read x = 3, y = 1, s = 3 spare, P = 11.
  6. Try it: change the profit per x and see which corner becomes best.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

πŸ€” Common doubts, cleared

Why add slack variables at all?

Row operations need equations, not inequalities. Slack turns each ≀ into =, and its value shows the unused resource. Step 2 shows the three slack bars.

Why choose the most negative entry?

In P βˆ’ 3x βˆ’ 2y = 0, raising x adds 3 to P per unit, the biggest gain. Step 3 shows P jump to 9.

Why the smallest ratio and not the largest?

The smallest ratio is the first constraint to run out; going further leaves the green region. Step 3: the ball stops at x = 3.

How do I know when to stop?

When the P row has no negative entries no edge improves P. Step 5 shows the final row 0, 0, 2, 0, 1 | 11.

Is the simplex answer the same as the graphical one?

Yes. It checks corners in a smart order. Step 6 shows the tallest pillar matches.

What happens if the objective changes?

A different corner may become optimal. Move the slider in step 6 and watch the star move.

From graph to algebra: why simplex?

In the graphical method, the best value of a linear objective always lies at a corner (vertex) of the feasible region. With 3 or more variables you cannot draw the region, so we need an algebraic way to walk from corner to corner.

The simplex algorithm starts at one corner (usually the origin) and moves along an edge to a neighbouring corner that improves the objective. It stops when no neighbour is better.

Slack variables and the initial tableau

A slack variable measures the unused amount of a resource. For x + y ≀ 4 write x + y + r = 4 with r β‰₯ 0.

Example: maximise P = 3x + 2y subject to x + y ≀ 4, x + 3y ≀ 9, x ≀ 3, x, y β‰₯ 0. Rewrite the objective as P βˆ’ 3x βˆ’ 2y = 0.

BasicxyrstValue
r111004
s130109
t100013
Pβˆ’3βˆ’20000

The basic variables (r, s, t) have a column with one 1 and zeros. Non-basic variables (x, y) are 0. So this tableau describes the corner (0, 0) with P = 0.

The pivot: column, ratio test, row operations

  1. Pivot column: the most negative entry in the objective row (here x, βˆ’3). Increasing x raises P fastest per unit.
  2. Ratio test: for each row with a positive entry in that column, find value Γ· entry: 4/1, 9/1, 3/1. The smallest (3, row t) is the pivot row. It is the first constraint to run out.
  3. Make the pivot 1: divide the pivot row by the pivot element.
  4. Clear the column: add or subtract multiples of the pivot row so every other entry in the column is 0.
  5. The entering variable (x) replaces the leaving one (t) in the basic list.

After pivot 1: x = 3, r = 1, s = 6, P = 9 (corner (3, 0)). P row: 0, βˆ’2, 0, 0, 3 | 9. Still negative (βˆ’2), so pivot on y: ratios 1/1 = 1 and 6/3 = 2, so row r. After pivot 2 the P row is 0, 0, 2, 0, 1 | 11.

Reading a simplex tableau

Minimising with simplex, and β‰₯ constraints

To minimise C, maximise P = βˆ’C and use the same steps; at the end, C = βˆ’P.

Example: minimise C = x βˆ’ 2y with x + y ≀ 6, y ≀ 4. Maximise P = βˆ’x + 2y: P row is 1, βˆ’2. Pivot on y (ratios 6 and 4 β†’ row 2): y = 4, P = 8, so the minimum C = βˆ’8 at (0, 4).

If a constraint is β‰₯, the origin is not feasible. Then you subtract a surplus variable and add an artificial variable, and use the two-stage method (first remove the artificials) or the big-M method (give artificials a huge penalty M).

Try it: check with corners

List all corners of the feasible region for the example: (0, 0), (3, 0), (3, 1), (1.5, 2.5), (0, 3). Work out P = 3x + 2y at each. Does the largest match the simplex answer 11? Now change the objective to P = x + 2y and run the simplex again. Which corner wins? (Use the slider in the 3D to check.)

Key formulas and definitions

Worked examples

1. Write the constraints x + 2y ≀ 10 and 3x + y ≀ 15 with slack variables.

x + 2y + s₁ = 10 and 3x + y + sβ‚‚ = 15, with s₁, sβ‚‚ β‰₯ 0.

2. Maximise P = 5x + 4y subject to 2x + y ≀ 8, x + 2y ≀ 7, x, y β‰₯ 0. Do the first pivot.

P row: βˆ’5, βˆ’4. Pivot column x (βˆ’5). Ratios: 8/2 = 4, 7/1 = 7 β†’ row 1, pivot 2. Divide row 1 by 2: x + 0.5y + 0.5r = 4. Row 2 βˆ’ row 1: 1.5y βˆ’ 0.5r + s = 3. P row + 5Γ—row 1: βˆ’1.5y + 2.5r = 20. So x = 4, s = 3, P = 20.

3. Finish the problem in example 2.

P row still has βˆ’1.5 under y. Ratios: 4/0.5 = 8, 3/1.5 = 2 β†’ row 2, pivot 1.5. Divide: y βˆ’ r/3 + 2s/3 = 2. Row 1 βˆ’ 0.5Γ—new row: x + 2r/3 βˆ’ s/3 = 3. P row + 1.5Γ—new row: 2r + s = 23. No negatives, so optimal: x = 3, y = 2, P = 23.

4. Minimise C = x βˆ’ 2y subject to x + y ≀ 6, y ≀ 4, x, y β‰₯ 0.

Maximise P = βˆ’x + 2y, so P + x βˆ’ 2y = 0. Pivot column y (βˆ’2). Ratios 6/1 = 6, 4/1 = 4 β†’ row 2. Then y = 4, first slack = 2, P row: 1, 0, 0, 2 | 8. Optimal: P = 8, so C = βˆ’8 at x = 0, y = 4.

5. A final tableau has rows: x | 1 0 0.5 βˆ’0.5 | 6; y | 0 1 βˆ’0.25 0.75 | 2; P | 0 0 1.5 0.5 | 42 (columns x, y, s₁, sβ‚‚). Read the solution.

No negatives in the P row β†’ optimal. Basic: x = 6, y = 2. Non-basic: s₁ = sβ‚‚ = 0 (both resources fully used). P = 42. Each extra unit of resource 1 would add 1.5 to P.

6. Maximise P = 3x + 2y + 4z subject to x + y + 2z ≀ 4, 2x + y + 3z ≀ 5, x, y, z β‰₯ 0.

Pivot 1: z (βˆ’4); ratios 4/2 = 2, 5/3 β‰ˆ 1.67 β†’ row 2. Gives P = 20/3 with P row βˆ’1/3 (x), βˆ’2/3 (y). Pivot 2: y; ratios 2 (row 1) and 5 β†’ row 1. P = 8 but x still has βˆ’1. Pivot 3: x; only row z has a positive entry (ratio 1). Final: x = 1, y = 3, z = 0, P = 9. Check: 1 + 3 = 4 βœ“, 2 + 3 = 5 βœ“.

Common mistakes

Practice quiz

1. A slack variable measures…
2. When maximising, the pivot column is the one with…
3. The ratio test uses…
4. A maximising tableau is optimal when…
5. To minimise C with simplex you…

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is the simplex method?

An algorithm that solves linear programming problems by moving from one corner of the feasible region to a better one using tableau row operations until no improvement is possible.

What is a slack variable?

A non-negative variable added to a ≀ constraint to make it an equation; it equals the unused amount of that resource.

How do you minimise using the simplex method?

Maximise the negative of the objective (P = βˆ’C) with the usual steps, then C = βˆ’P.

Where this is taught

England (GCSE, A level)Year 13Optional application 3 Discrete (part 2)

Learn first

Learn next

Related lessons

All Maths lessons