functionqp()% Copyright 2025, Gurobi Optimization, LLC%% This example formulates and solves the following simple QP model:% minimize% x^2 + x*y + y^2 + y*z + z^2 + 2 x% subject to% x + 2 y + 3 z >= 4% x + y >= 1% x, y, z non-negative%% It solves it once as a continuous model, and once as an integer% model.names={'x','y','z'};model.varnames=names;model.Q=sparse([10.50;0.510.5;00.51]);model.A=sparse([123;110]);model.obj=[200];model.rhs=[41];model.sense='>';gurobi_write(model,'qp.lp');results=gurobi(model);forv=1:length(names)fprintf('%s %e\n',names{v},results.x(v));endfprintf('Obj: %e\n',results.objval);model.vtype='B';results=gurobi(model);forv=1:length(names)fprintf('%s %e\n',names{v},results.x(v));endfprintf('Obj: %e\n',results.objval);end
Help and Feedback