Last active
February 20, 2017 13:34
-
-
Save VincentTam/2cb751550765ca20f993a847f102e0d4 to your computer and use it in GitHub Desktop.
My Octave simplex tableau generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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