0% found this document useful (0 votes)
25 views

Function: % I Is The Entering Basic Variable Column

This document describes a MATLAB function to perform the simplex method. It takes an input matrix A in canonical form, finds the entering and leaving basic variables at each iteration, and performs row operations to update the simplex table. It iterates until an optimal solution is found or no further iterations are possible.

Uploaded by

Leon Ramlall
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Function: % I Is The Entering Basic Variable Column

This document describes a MATLAB function to perform the simplex method. It takes an input matrix A in canonical form, finds the entering and leaving basic variables at each iteration, and performs row operations to update the simplex table. It iterates until an optimal solution is found or no further iterations are possible.

Uploaded by

Leon Ramlall
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

function SimplexUsingMATLAB()

clc
format compact
format rational
A =[2 5 2 1 0 0 38;4 2 3 0 1 0 57;1 3 5 0 0 1 57;-2 -6 -4 0 0 0 0];
[n m]= size(A);
fprintf('This is Table 1 - note the canonical form\n'),disp(A);
for iloop = 1:m
[val ebv] = min(A(n,:));
if val < 0
fprintf('\nEntering Basic Variable Column : '),disp(ebv);
lbv = LBV(A,ebv);
fprintf('\nLeaving Basic Variable (Pivot Row) : '),disp(lbv)
else
fprintf('\nNo further iterations possible')
fprintf('\nYou may have the solution')
fprintf('\nFinal table :')
format short g;
fprintf('\n-------------\n'),disp(A);
break;
end
if lbv > 0
A = RowOperations(A,ebv,lbv);
textstr = strcat('Simplex Table :',num2str(iloop+1));
disp(textstr);
disp(A);

end
end

function ret = LBV(A,i)


% i is the entering basic variable column
[n m] = size(A);
j = 0; min = 1000;
for k = 1:n
if A(k,i) > 0
row = A(k,m)/A(k,i);
if row < min
min = row; j = k;
end
end
end

if j == 0
fprintf('Not possible to evaluate EBV ');
end
ret = j;

function ret = RowOperations(A,i,j)


% i is the EBV column
% j is the pivot row
[n m] = size(A);
A(j,:) = A(j,:)/A(j,i);
for k = 1: n
if (k ~= j)
A(k,:) = A(k,:) - A(k,i)*A(j,:);
end
end
ret = A;

You might also like