function [t,inb,otb,x,v,n] = simplex(f,A,b,tol) % % returns the solutions to the linear programming problem % % max f'*x subject to A*x <= b, and x >= 0. % % on entry: % f coefficients of the linear objective function; % A coefficients of the linear inequalities; % b right hand side vector of the constraints; % tol tolerance to decide whether a number is zero. % % on return: % t final tableau; % inb indices to variables in the basis, % inb(i) gives column for i-th unit vector; % otb indices to variables outside the basis; % x extended solution vector, the first size(A,2) % entries gives values for the original x variables; % v value of the objective function at the solution; % n number of pivoting steps. % % example: % f = [3 5]' % A = [1 0; 0 2; 3 2] % b = [4 12 18]' % tol = 1.0e-8; % [t,inb,otb,x,v,n] = simplex(f,A,b,tol) % f'*x(1:2)' % check value of f'*x % A*x(1:2)' % verify if x satisfies A*x <= b % % simplex needs initialize.m, entering.m, leaving.m, diagonalize.m, % passing.m, and solution.m % [t,inb,otb] = initialize(f,A,b); % initialize tableau e = entering(t,otb); % compute entering variable n = 0; while (e ~= 0) % as long as not optimal l = leaving(t,e,tol); % compute leaving variable if (l == 0) break; end; % solution may be unbounded t = diagonalize(t,e,l,tol); % diagonalize tableau [inb,otb] = passing(inb,otb,e,l); % update the basis n = n+1; % count #pivoting steps e = entering(t,otb); % new entering variable end; [x,v] = solution(t,inb); % compute solution