I have a program, which makes Gauss-Jordan transformations (not too pretty, I suppose). I want to get output with Manipulator like that: Two-Phase Simplex Method with only "step number" slider. One table for each step. Is it possible?
Matrix:
A = {{6, 15, 6, 1, 0, 0, 9}, {14, 42, 16, 0, 1, 0, 21}, {2, 8, 2, 0,
0, 1, 4}, {10, -7, -5, 0, 0, 0, 0}};
Code:
Clear[GaussJordanStep]
GaussJordanStep[M_] := Module[{i, j, m, n, a, b, B = M},
{m, n} = Dimensions@M;
{a, b} =
Flatten@Thread[{First@
Ordering[
Replace[Thread[{Flatten@
M[[;; -2, Flatten@Position[Last@M, Min[Last@M]]]] ,
M[[;; -2, -1]]}], {{x1_?Positive, x2_} :> x2/x1,
else_ :> \[Infinity]}, {1}]],
Position[Last@M, Min[Last@M]]}];
For[i = 1, i <= m, i++,
For[j = 1, j <= n, j++,
If[i == a, B[[i, j]] = M[[i, j]]/M[[a, b]],
B[[i, j]] = M[[i, j]] - (M[[i, b]] M[[a, j]])/M[[a, b]]]]];
B]
Clear[SimplexMethod]
SimplexMethod[M_] := Module[{B = M},
Print[Grid[B, Dividers -> {-2 -> True, -2 -> True}]];
Do[B = GaussJordanStep[B]; Print[Grid[B, Dividers -> {-2 -> True, -2 -> True}]];
If[Length@Position[B[[-1]], _?Negative] > 0, Continue[],
Break[]], {100}]]
Program output:
SimplexMethod[A]