I believe to be missing something important in the Simplex algorithm, because I can't get it to work.
From what I gather, there are three steps per iteration, given a matrix for a linear program in standard form:
- Look for negative terms in the objective function's row.
- If you find one, look for the pivot if there is any.
- We need to transform the pivot into a 1 and all other terms in the column to 0 using row operations.
- Repeat
Well then:
$$min z = x_2-x_1 + 1$$
subject to
$$\begin{cases}-2x_1 + x_2 \le 2\\ x_1 - 2x_2 \le 2\\ x_1+x_2 \le 5\\ x_i \le 0 \forall i \end{cases}$$
We require the standard form. We convert the inequalities to equations:
$$\begin{cases}-2x_1 + x_2 + x_3 + 0 + 0= 2\\ x_1 - 2x_2 + 0 + x_4 + 0 = 2\\ x_1+x_2 + 0 +0 + x_5= 5\\ x_i = 0 \forall i \end{cases}$$
We have the following matrix, where the last row represents the objective function:
$$\begin{bmatrix} -2 & 1 & 1 & 0 & 0 & 2 \\ 1 & -2 & 0 & 1 & 0 & 2 \\ 1 & 1 & 0 & 0 & 1 & 5 \\ -1 & 1 & 0 & 0 & 0 & z - 1 \end{bmatrix}$$
We proceed with the Simplex algorithm.
First iteration
Step 1: Look for negative terms in the objective function. The first column has a $-1$.
Step 2: Find the pivot. It is the first $1$ in the first column.
Step 3: We require the pivot to be $1$ and the rest of the column to be $0$. We do this with elemental row operations:
$$\begin{bmatrix} -2 & 1 & 1 & 0 & 0 & 2 \\ [1] & -2 & 0 & 1 & 0 & 2 \\ 1 & 1 & 0 & 0 & 1 & 5 \\ -1 & 1 & 0 & 0 & 0 & z - 1 \end{bmatrix}$$
$$2r_2 + r_1$$
$$\begin{bmatrix} 0 & -3 & 1 & 2 & 0 & 6 \\ [1] & -2 & 0 & 1 & 0 & 2 \\ 1 & 1 & 0 & 0 & 1 & 5 \\ -1 & 1 & 0 & 0 & 0 & z - 1 \end{bmatrix}$$
$$r_3 + r_4$$
$$\begin{bmatrix} 0 & -3 & 1 & 2 & 0 & 6 \\ [1] & -2 & 0 & 1 & 0 & 2 \\ 1 & 1 & 0 & 0 & 1 & 5 \\ 0 & 2 & 0 & 0 & 1 & z + 4 \end{bmatrix}$$
$$-r_2 + r_3$$
$$\begin{bmatrix} 0 & -3 & 1 & 2 & 0 & 6 \\ [1] & -2 & 0 & 1 & 0 & 2 \\ 0 & 3 & 0 & -1 & 1 & 3 \\ 0 & 2 & 0 & 0 & 1 & z + 4 \end{bmatrix}$$
Second iteration
Step 1: Look for negative terms in the objective function. There are none. The algorithm ends.
... But I know this is wrong, because according to the exercise's answer, I should have ended up with matrix of the form
$$\begin{bmatrix} 0 & 0 & 1 & 1 & 1 & 9 \\ 1 & 0 & 0 & 1/3 & 2/3 & 4 \\ 0 & 1 & 0 & -1/3 & 1/3 & 1 \\ 0 & 0 & 0 & 2/3 & 1/3 & z + 2 \end{bmatrix}$$
And done three iterations. Unfortunately the details of those iterations are not shown so I'm not sure what did I do wrong.