Skip to content

Instantly share code, notes, and snippets.

@VincentTam
Last active February 20, 2017 13:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VincentTam/2cb751550765ca20f993a847f102e0d4 to your computer and use it in GitHub Desktop.
Save VincentTam/2cb751550765ca20f993a847f102e0d4 to your computer and use it in GitHub Desktop.
My Octave simplex tableau generator
# Show simplex tableau
# Prereq: matrix A, vectors b,c, basis
printf("Current basis:"); printf(" %2i", basis); disp("");
B = A(:,basis); cB = c(basis);
Bm1A = B\A; x_B = B\b; zrow = cB'*Bm1A-c'; zval = cB'*x_B;
nv = find(zrow==min(zrow(zrow<=0)))(1);
r = x_B./Bm1A(:,nv);
T = [0:size(A)(2) 0 0; basis' Bm1A x_B r; 0 zrow zval 0]
if length(r(r>=0)) >= 1
ovp = find(r==min(r(r>=0)))(1);
printf("Leaving variable: %i\nEntering variable: %i\n", basis(ovp), nv);
basis(ovp) = nv;
else
disp("Simplex ended");
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment