## Maximalize(and minimalize) the function by using simplex algorythm

Hi guys. I was solving 3 problems of this kind, two went pretty good, I will just ask if they are correct and the 3rd one... Yeah , I couldn't manage to finish it ,so I would need a petite help Well I'm not very good in using latex so it looks how it looks, I hope you won't have a problem to read the algorythms So here it is:

Problem nr 1 (solved, tell me if it's correct ):

With use of simplex algorythm,maximalize the following function:$\displaystyle \phi(x)=2x_{2}-2x_{3}-2x_{4}\$ with: $\displaystyle $x\geq 0$$ oraz $\displaystyle A*x\leq b$:
$\displaystyle A=\begin{pmatrix} -1 & 1 & 0 & 1\\ 1 & 1 & -4 & 3\\ 1 & -1 & 2 & 2\\ 0 & 1 & -2 & -1 \end{pmatrix} ,b=\begin{pmatrix} 4\\ 12\\ 5\\ 5 \end{pmatrix}$
And this is what I've done myself
$\displaystyle \begin{vmatrix} &x_{1} & x_{2}& x_{3} & x_{4} & x_{5} & x_{6} &x_{7} &x_{8} & b\\ x_{5} & -1 &1 &0 &1 &1 &0 &0 &0 &4\\ x_{6} & 1 & 1 &-4 &3 &0 &1 &0 &0 &12 \\ x_{7} & 1 & -1 &2 &2 &0 &0 &1 &0 &5 \\ x_{8} & 0 &1 &-2 &-1 &0 &0 &0 &1 &5 \\ \phi &0 &- 2 & 2 &2 &0 &0 &0 &0 &0 \end{vmatrix}$
I don't know if you use the same name , but now I have to chose Pivot element(?).I took the $\displaystyle x_{5},x_{2}=1$.After I've done the following actions: II. line - I. line, III. line + I. line,IV. line - I.line , V.line + 2*I.line. Results:
$\displaystyle \begin{vmatrix} &x_{1} & x_{2}& x_{3} & x_{4} & x_{5} & x_{6} &x_{7} &x_{8} & b\\ x_{2} & -1 &1 &0 &1 &1 &0 &0 &0 &4\\ x_{6} & 2 & 0 &-4 &2 &-1 &1 &0 &0 &8 \\ x_{7} & 0 & 0 &2 &3 &1 &0 &1 &0 &9 \\ x_{8} & 1 &0 &-2 &-2 &-1 &0 &0 &1 &1 \\ \phi &-2 &0 & 2 &4 &2 &0 &0 &0 &8 \end{vmatrix}$
Now my Pivot element is: $\displaystyle x_{8},x_{1}=1$. My following actions: I + IV , II - 2*IV, III without changes, V +2*IV, Results :
$\displaystyle \begin{vmatrix} &x_{1} & x_{2}& x_{3} & x_{4} & x_{5} & x_{6} &x_{7} &x_{8} & b\\ x_{2} & 0 &1 &-2 &-1 &0 &0 &0 &1 &5\\ x_{6} & 0 & 0 &0 &6 &1 &1 &0 &-2 &6 \\ x_{7} & 0 & 0 &2 &3 &1 &0 &1 &0 &9 \\ x_{1} & 1 &0 &-2 &-2 &-1 &0 &0 &1 &1 \\ \phi &0 &0 & -2 &0 &0 &0 &0 &2 &10\end{vmatrix}$
Pivot element: $\displaystyle x_{7},x_{3}=2$. Following actions : I + III, II without changes, IV + III, V +III. Results :
$\displaystyle \begin{vmatrix} &x_{1} & x_{2}& x_{3} & x_{4} & x_{5} & x_{6} &x_{7} &x_{8} & b\\ x_{2} & 0 &1 &0 &2 &1 &0 &1 &1 &14\\ x_{6} & 0 & 0 &0 &6 &1 &1 &0 &-2 &6 \\ x_{3} & 0 & 0 &2 &3 &1 &0 &1 &0 &9 \\ x_{1} & 1 &0 &0 &1 &0 &0 &1 &1 &10 \\ \phi &0 &0 & 0 &3 &1 &0 &1 &2 &19\end{vmatrix}$

Answer: $\displaystyle x_{1}=10,x_{2}=14,x_{3}=9,x_{4}=0,\phi(x)=19$

Btw: I was using so called 3 Phase method , I hope it tells you anything...

Problem nr 2 (also just tell me if it's correct or not )
With use of simplex algorythm,maximalize the following function : $\displaystyle \phi(x)=4x_{1}+3x_{3}+x_{4}$ with $\displaystyle x\geq 0$ and:

$\displaystyle x_{1}-x_{2}+3x_{3}+x_{4}\leq 8$
$\displaystyle -x_{1}-5x_{2}+2x_{3}+2x_{4}\geq 2$
$\displaystyle x_{1}-2x_{2}-x_{3}+x_{4}\leq 4$
$\displaystyle 3x_{2}-x_{4}=1$
$\displaystyle -2x_{2}+2x_{3}+x_{4}=4$

Now I needed to create the algorythm.I need to maximalize the function so I multiplied the funtion $\displaystyle \phi$ with -1.I also needed to change the signs in 1st and 3rd inequality so I also multiplied them with -1. It was written in instructions for 3 Phase method ,so I did so And my algorythm looks like this:
$\displaystyle \begin{vmatrix} & x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &1 &-1 &3 &1 &1 &0 &0 &8 \\ x_{6} &1 &5 &-2 &-2 &0 &1 &0 &-2 \\ x_{7} &1 &-2 &-1 &1 &0 &0 &1 &4 \\ y_{8} &0 &3 &0 &-1 &0 &0 &0 &1 \\ y_{9} &0 &-2 &2 &1 &0 &0 &0 &4 \\ \phi &-4 &0 &-3 &-1 &0 &0 &0 &0 \end{vmatrix}$
Pivot element : $\displaystyle y_{9},x_{4}=1$ . In the description of the problem,it was written,in phase 0 to chose an element that will not follow to decimal numbers. Following actions: I - V , II + 2* V , III - V , IV + V, VI + V. Results:
$\displaystyle \begin{vmatrix} & x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &1 &1 &1 &0 &1 &0 &0 &4 \\ x_{6} &1 &1 &2 &0 &0 &1 &0 &6 \\ x_{7} &1 &0 &-3 &0 &0 &0 &1 &0 \\ y_{8} &0 &1 &2 &0 &0 &0 &0 &5 \\ x_{4} &0 &-2 &2 &1 &0 &0 &0 &4 \\ \phi &-4 &-2 &-1 &0 &0 &0 &0 &4 \end{vmatrix}$
Pivot element: $\displaystyle y_{8},x_{2}=1$ .Following equations: I - IV , II - IV , III without changes , V + 2*IV , VI + 2*IV. Results:
$\displaystyle \begin{vmatrix} & x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &1 &0 &-1 &0 &1 &0 &0 &-1 \\ x_{6} &1 &0 &0 &0 &0 &1 &0 &1 \\ x_{7} &1 &0 &-3 &0 &0 &0 &1 &0 \\ x_{2} &0 &1 &2 &0 &0 &0 &0 &5 \\ x_{4} &0 &0 &6 &1 &0 &0 &0 &14 \\ \phi &-4 &0 &3 &0 &0 &0 &0 &14 \end{vmatrix}$
Pivot element: $\displaystyle x_{6},x_{1}=1$ . Following equations: I - II, III - II, IV without changes, V without changes, VI + 4*II , Results :
$\displaystyle \begin{vmatrix} & x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &0 &0 &-1 &0 &1 &-1 &0 &-2 \\ x_{1} &1 &0 &0 &0 &0 &1 &0 &1 \\ x_{7} &0 &0 &-3 &0 &0 &-1 &1 &-1 \\ x_{2} &0 &1 &2 &0 &0 &0 &0 &5 \\ x_{4} &0 &0 &6 &1 &0 &0 &0 &14 \\ \phi &0 &0 &3 &0 &0 &4 &0 &18 \end{vmatrix}$
In line $\displaystyle \phi$ all elements are $\displaystyle \geq 0$, so I can already finish the algorythm and have following results:
Answer: $\displaystyle x_{1}=1,x_{2}=5,x_{3}=0,x_{4}=14,\phi(x)=18$

Problem nr 3 ( this is where I need your helps solving this )
With use of simplex algorythm, minimalize following function : $\displaystyle \phi(x)=2x_{1}+5x_{2}+x_{4}$ and :

$\displaystyle x_{1}+3x_{3}\geq 4$
$\displaystyle 2x_{1}+5x_{2}+6x_{3}-x_{4}\leq 0$
$\displaystyle -x_{2}-x_{3}+x_{4}\leq 0$
$\displaystyle x_{1}+2x_{2}+2x_{3}=5$

Of course first I've changed the sign in the first inequation and after created following algorythm:

$\displaystyle \begin{vmatrix} &x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &-1 &0 &-3 &0 &1 &0 &0 &-4 \\ x_{6} &2 &5 &6 &-1 &0 &1 &0 &0 \\ x_{7} &0 &1 &1 &-1 &0 &0 &1 &-2 \\ y_{8} &1 &2 &2 &0 &0 &0 &0 &5 \\ \phi &2 &5 &0 &1 &0 &0 &0 &0 \end{vmatrix}$
Pivot element : $\displaystyle y_{8},x_{1}=1$ (of course it was written to chose an element in phase 0, that will not result in decimal numbers) .Equations : I + IV, II - 2*IV, III without changes , V - 2*IV. Results:
$\displaystyle \begin{vmatrix} &x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &0 &2 &-1 &0 &1 &0 &0 &1 \\ x_{6} &0 &1 &2 &-1 &0 &1 &0 &-10 \\ x_{7} &0 &1 &1 &-1 &0 &0 &1 &-2 \\ x_{1} &1 &2 &2 &0 &0 &0 &0 &5 \\ \phi &0 &1 &-4 &1 &0 &0 &0 &-10 \end{vmatrix}$
Pivot element : $\displaystyle x_{6},x_{2}=1$ .Equations : I - 2*II, III-II, IV-2*II, V-II, Results:
$\displaystyle \begin{vmatrix} &x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{5} &0 &0 &-5 &2 &1 &-2 &0 &21 \\ x_{2} &0 &1 &2 &-1 &0 &1 &0 &-10 \\ x_{7} &0 &0 &-1 &0 &0 &-1 &1 &8 \\ x_{1} &1 &0 &-2 &2 &0 &-2 &0 &25 \\ \phi &0 &0 &-6 &2 &0 &-1 &0 &0 \end{vmatrix}$
Pivot element : $\displaystyle x_{5},x_{4}=2$ . First, i divided this line through 2 so the pivot element could be = 1. And after following equations : II+I, III without changes, IV- 2*II, V-2*II ,Results:
$\displaystyle \begin{vmatrix} &x_{1} &x_{2} &x_{3} &x_{4} &x_{5} &x_{6} &x_{7} &b \\ x_{4} &0 &0 &-2,5 &1 &0,5 &-1 &0 &10,5 \\ x_{2} &0 &1 &-0,5 &0 &0,5 &0 &0 &0,5 \\ x_{7} &0 &0 &-1 &0 &0 &-1 &1 &8 \\ x_{1} &1 &0 &3 &0 &-1 &1 &1 &-13 \\ \phi &0 &0 &-1 &0 &-1 &1 &0 &-21 \end{vmatrix}$
Till here it's fine but from now one everything starts to be complicated and senseless. Theoretically now I need to chose a column where $\displaystyle \phi$ is higher than 0. So I have this "1". So ok, I chose the last line ,which wasn't changed yet $\displaystyle x_{6}$,but after equations I still have one element of $\displaystyle \phi$ ,which is positive,and it shouldn't be so... So I don't know where I went wrong... Anyone has some ideas? Thanks