linear-programming-using-MATLAB icon indicating copy to clipboard operation
linear-programming-using-MATLAB copied to clipboard

standard2canonical.m wrong implementation

Open mh510 opened this issue 6 years ago • 0 comments

Hi, a great book first of all. I found an error in the file standard2canonical.m and the corresponding text is also misleading. On page 15 (29/639) it says: "Finally, we remove variable x1 from the objective function and the other constraints.". You forgot to insert the equation for x1 into the other equations as you did in the following example on the same page.

Here's my sloppy implementation (assuming that we just have equality constraints):

function [A, c, b] = standard2canonical0(A, c, b)
[m,~] = size(A);
for i = 1:m
    s = find(A(i,:) ~= 0);
    s = s(1);
    
    as = A(i,s);
    cs = c(s);
    As = A(i,:);
    bs = b(i);
    
    c = c-cs/as*As';
    
    for j = 1:m
        if j == i
            A(j,:) = A(j,:)/as;
            b(j) = b(j)/as;
        else
            ajs = A(j,s);
            A(j,:) = A(j,:)-ajs/as*As;
            b(j) = b(j)-ajs/as*bs;
        end
    end
    
    c(s) = [];
    A(:,s) = [];
end
end

mh510 avatar Oct 11 '18 08:10 mh510