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 the HiGHS solver (WASM).

c = [-1; -2];
A = [1 1; 1 3];
b = [4; 6];
[x, fval] = linprog(c, A, b);
printf('Optimal: x = [%.1f, %.1f], cost = %.1f', x(1), x(2), fval)
▶ Run in SimLab

Expected output: Optimal solution

Step 2 — Model builder

Build models with named variables and constraints.

m = Model();
x = m.var('x', 0, 10);
y = m.var('y', 0, 10);
m.minimize(3*x + 5*y);
m.addConstraint(x + y >= 8);
m.addConstraint(2*x + y >= 10);
result = m.solve();
disp(result)
▶ Run in SimLab

Expected output: Optimal values for x and y

Related Tutorials

Try SimLab — Free MATLAB® Alternative

466 functions. Runs in your browser. No install.

Open SimLab

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.