%simplex
clc;
clear all;
cost=[2 5 0 0 0 0];
a=[ 1 4; 3 1 ; 1 1];
b=[24;21;9];
[m,n]=size(a);
s=eye(m);
A=[a s b];
%cost=zeros(1,n+m+1);
%cost(1:n)=c;
bv=n+1:n+m
zjcj=cost(bv)*A-cost;
zcj=[zjcj;A];
simptable=array2table(zcj);
simptable.Properties.VariableNames(1:size(zcj,2))={'x1','x2','s1','s2','s3','sol'}
flag=true;
while flag
if any(zjcj<0)
fprintf('current bfs is not optimal \n')
zc=zjcj(1:end-1);
[enter_val,pvt_col]=min(zc)
if all(A(:,pvt_col)<=0)
error('LPP is unbounded all enteries are <=0 in column %d',pvt_col);
else
sol=A(:,end)
column=A(:,pvt_col)
for i=1:m
if(column(i)>0)
ratio(i)= sol(i)./column(i)
else
ratio(i)=inf
end
end
[leaving_val, pvt_row] = min(ratio)
end
bv(pvt_row) = pvt_col;
pvt_key = A(pvt_row, pvt_col);
A(pvt_row, :) = A(pvt_row, :)/pvt_key;
for i=1:m
if i~=pvt_row
A(i, :) = A(i, :) -A(i, pvt_col).*A(pvt_row, :);
end
end
zjcj = cost(bv)*A-cost;
zcj = [zjcj;A];
table = array2table(zcj);
table.Properties.VariableNames(1:n+m+1)={'x1','x2','s1','s2','s3','sol'}
else
flag = false;
fprintf('The current bfs is optimal\n')
end
end
Cite As
Akshay (2026). ot-lab-simplex (https://in.mathworks.com/matlabcentral/fileexchange/128388-ot-lab-simplex), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2023a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
