Linear & Integer Programming
Mathematical Programmingintermediate~10 min
Solve optimization problems with linprog and the Model builder API.
Step 1 — linprog
Minimize c'x subject to Ax <= b using SimLab's FUSE-first LP stack (FUSE-LP on small/medium LPs, HiGHS fallback in the browser).
c = [-1; -2];
A = [1 1; 1 3];
b = [4; 6];
result = linprog(c, A, b);
printf('Optimal: x = [%.1f, %.1f], cost = %.1f', result.x(1), result.x(2), result.fval)▶ Run in SimLabExpected output: Optimal solution
Step 2 — Model builder
Build models with named variables and constraints.
m = Model('minimize');
x = m.addVar('x', 0, 10);
y = m.addVar('y', 0, 10);
m.setObjective(3*x + 5*y);
m.addConstr(x + y >= 8, 'c1');
m.addConstr(2*x + y >= 10, 'c2');
result = m.solve();
disp(result)▶ Run in SimLabExpected output: Optimal values for x and y
Related Tutorials
Try SimLab — MATLAB®-compatible, free, in your browser
466 functions. Runs in your browser. No install.
Open SimLabMATLAB® is a registered trademark of The MathWorks, Inc. SimLab is an independent project by Simulations4All and is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.