Model()

Mathematical Programming

Model() is a MATLAB®-compatible mathematical programming function for create an optimization model for lp, mip, or qp. methods: m.addvar(name, lb, ub) — continuous variable m.addvar(name, 'binary') — binary (0/1) variable m.addvar(name, lb, ub, 'integer') — integer variable m.addvars(n, name, ...) — 1d array of variables m.addvars([r,c], name, ...) — 2d array of variables m.setobjective(expr) — set linear/quadratic objective m.addconstr(expr, 'name') — add constraint (<=, >=, ==) result = m.solve() — solve and return result linear models route through the same fuse-first browser solver stack as linprog/intlinprog. result fields: status, objval, vars, duals, exitflag, solvetime. Run it online in your browser with SimLab — free, no install, no license required.

Create an optimization model for LP, MIP, or QP. Methods: m.addVar(name, lb, ub) — continuous variable m.addVar(name, 'binary') — binary (0/1) variable m.addVar(name, lb, ub, 'integer') — integer variable m.addVars(n, name, ...) — 1D array of variables m.addVars([r,c], name, ...) — 2D array of variables m.setObjective(expr) — set linear/quadratic objective m.addConstr(expr, 'name') — add constraint (<=, >=, ==) result = m.solve() — solve and return result Linear models route through the same FUSE-first browser solver stack as linprog/intlinprog. Result fields: status, objVal, vars, duals, exitflag, solveTime

Syntax

m = Model('minimize')
m = Model('maximize')

Examples — run Model() in your browser

% LP: Product mix
m = Model('maximize')
x = m.addVar('tables', 0, Inf)
y = m.addVar('chairs', 0, Inf)
m.setObjective(70*x + 50*y)
m.addConstr(4*x + 3*y <= 240, 'wood')
result = m.solve()
▶ Run
% MIP: Knapsack with addVars
m = Model('maximize')
items = m.addVars(3, 'x', 'binary')
val = [10, 8, 3]
m.setObjective(val * items)
m.addConstr([5, 4, 1] * items <= 10)
result = m.solve()
▶ Run

See Also

More Mathematical Programming Functions

Browse other free, MATLAB®-compatible mathematical programming functions in SimLab:

Browse all 510+ SimLab functions →

Frequently Asked Questions about Model()

Is the Model() function free to use in SimLab?

Yes. SimLab is 100% free — no signup, no license, and no usage limits. You can run Model() and 510+ other MATLAB®-compatible functions directly in your browser at simulations4all.com/simlab.

Do I need to install MATLAB to use Model()?

No. SimLab runs entirely in your web browser with zero installation. The Model() function works without any MATLAB® license or software download.

What does Model() do?

Create an optimization model for LP, MIP, or QP. Methods: m.addVar(name, lb, ub) — continuous variable m.addVar(name, 'binary') — binary (0/1) variable m.addVar(name, lb, ub, 'integer') — integer variable m.addVars(n, name, ...) — 1D array of variables m.addVars([r,c], name, ...) — 2D array of variables m.setObjective(expr) — set linear/quadratic objective m.addConstr(expr, 'name') — add constraint (<=, >=, ==) result = m.solve() — solve and return result Linear models route through the same FUSE-first browser solver stack as linprog/intlinprog. Result fields: status, objVal, vars, duals, exitflag, solveTime. It is a MATLAB®-compatible mathematical programming function available in SimLab with the same calling syntax as MATLAB® — typically: m = Model('minimize').

Can I run Model() in my browser?

Yes. Open SimLab at simulations4all.com/simlab, write or paste code that calls Model(), and run it. Execution happens locally in your browser — no data leaves your machine.

Try SimLab — MATLAB®-compatible, free, in your browser

510+ functions. Runs in your browser. No install. No license.

Open SimLab

MATLAB® 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.

Stay Updated

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