Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# lp.m

    function lp()
    % Copyright 2025, Gurobi Optimization, LLC
    %
    % This example formulates and solves the following simple LP model:
    % maximize
    %       x + 2 y + 3 z
    % subject to
    %       x +   y        <= 1
    %             y +   z  <= 1
    %

    model.A = sparse([1 1 0; 0 1 1]);
    model.obj = [1 2 3];
    model.modelsense = 'Max';
    model.rhs = [1 1];
    model.sense = [ '<' '<'];

    result = gurobi(model);

    disp(result.objval);
    disp(result.x);

    % Alterantive representation of A - as sparse triplet matrix
    i = [1; 1; 2; 2];
    j = [1; 2; 2; 3];
    x = [1; 1; 1; 1];
    model.A = sparse(i, j, x, 2, 3);

    % Set some parameters
    params.method = 2;
    params.timelimit = 100;

    result = gurobi(model, params);

    disp(result.objval);
    disp(result.x)
    end

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support