Skip to content

standard2canonical.m wrong implementation #1

Open
@mh510

Description

@mh510

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions