Try our new documentation site (beta).


function opttoolbox_lp()
% Copyright 2023, Gurobi Optimization, LLC
% This example uses Matlab 2017b problem based modeling feature, which
% requires Optimization Toolbox, to formulate and solve the following
% simple LP model, the same model as for lp.m
% maximize
%       x + 2 y + 3 z
% subject to
%       x +   y        <= 1
%             y +   z  <= 1
% To use Gurobi with this example, linprog.m must be in the current
% directory or added to Matlab path

x = optimvar('x', 'LowerBound',0);
y = optimvar('y', 'LowerBound',0);
z = optimvar('z', 'LowerBound',0);

prob = optimproblem('ObjectiveSense','maximize');

prob.Objective = x + 2 * y + 3 * z;

prob.Constraints.cons1 = x + y <= 1;
prob.Constraints.cons2 = y + z <= 1;

options = optimoptions('linprog');

% For Matlab R2017b use the following
% sol = solve(prob, options)

% Syntax for R2018a and later
sol = solve(prob, 'Options', options);

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.