Error in dual simplex algorithm
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a code for dual simplex algorithm, given below. But i am not able to rectify the error shown by this code. I want to run the code for the following constraints, type = 'min'; c = [-2 3 4]; A = [-1 –1 –1;2 2 2]; b = [-1;4]; "subs = dsimplex(type, c, A, b)" . Please help me to sort the error.
function varargout = dsimplex(type, c, A, b)
% The Dual Simplex Algorithm for solving the LP problem
% min (max) z = c*x
% Subject to Ax >= b
% x >= 0
%
if type == 'min'
mm = 0;
else
mm = 1;
c = -c;
end
str = 'Would you like to monitor the progress of computations?';
A = -A;
b = -b(:);
c = c(:)';
[m, n] = size(A);
A = [A eye(m) b];
A = [A;[c zeros(1,m+1)]];
question_ans = questdlg(str,'Make a choice Window','Yes','No','No');
if strcmp(question_ans,'Yes')
p1 = 'y';
else
p1 = 'n';
end
if p1 == 'y'
disp(sprintf('\n\n Initial tableau'))
A
disp(sprintf(' Press any key to continue ...\n\n'))
pause
end
subs = n+1:n+m;
[bmin, row] = Br(b);
tbn = 0;
while ~isempty(bmin) & bmin < 0 & abs(bmin) > eps
if A(row,1:m+n) >= 0
disp(sprintf('\n\n Empty feasible region\n'))
varargout(1)={subs(:)};
varargout(2)={A};
varargout(3) = {zeros(n,1)};
varargout(4) = {0};
return
end
col = MRTD(A(m+1,1:m+n),A(row,1:m+n));
if p1 == 'y'
disp(sprintf(' pivot row-> %g pivot column-> %g',...
row,col))
end
subs(row) = col;
A(row,:)= A(row,:)/A(row,col);
for i = 1:m+1
if i ~= row
A(i,:)= A(i,:)-A(i,col)*A(row,:);
end
end
tbn = tbn + 1;
if p1 == 'y'
disp(sprintf('\n\n Tableau %g',tbn))
A
disp(sprintf(' Press any key to continue ...\n\n'))
pause
end
[bmin, row] = Br(A(1:m,m+n+1));
end
x = zeros(m+n,1);
x(subs) = A(1:m,m+n+1);
x = x(1:n);
if mm == 0
z = -A(m+1,m+n+1);
else
z = A(m+1,m+n+1);
end
disp(sprintf('\n\n Problem has a finite optimal solution\n\n'))
disp(sprintf('\n Values of the legitimate variables:\n'))
for i=1:n
disp(sprintf(' x(%d)= %f ',i,x(i)))
end
disp(sprintf('\n Objective value at the optimal point:\n'))
disp(sprintf(' z= %f',z))
disp(sprintf('\n Indices of basic variables in the final tableau:'))
varargout(1)={subs(:)};
varargout(2)={A};
varargout(3) = {x};
varargout(4) = {z};
댓글 수: 1
cwshep
2015년 6월 20일
Please specify the error you are receiving. The only one I am getting is
Undefined function or variable 'Br'.
If I remove that line (but set bmin and brow) it completes successfully. It looks like you are just missing the Br function.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!