0001
0002 y0 = [1; 0];
0003 z0 = [0; 1];
0004
0005
0006 ymin = [0; 0];
0007 zmax = [0; 2];
0008
0009
0010 A1 = [ 6 1 5 -4 ]; b1 = 4;
0011 A2 = [ 4 9 ]; u2 = 2;
0012
0013
0014 Q = [ 8 1 -3 -4;
0015 1 4 -2 -1;
0016 -3 -2 5 4;
0017 -4 -1 4 12 ];
0018
0019
0020 opt = struct('verbose', 2, 'alg', 'MIPS');
0021
0022
0023
0024 om = opt_model;
0025 om.add_var('y', 2, y0, ymin);
0026 om.add_var('z', 2, z0, [], zmax);
0027 om.add_lin_constraint('lincon1', A1, b1, b1);
0028 om.add_lin_constraint('lincon2', A2, [], u2, {'y'});
0029 om.add_quad_cost('cost', Q, []);
0030
0031
0032 [x, f, exitflag, output, lambda] = om.solve();
0033
0034
0035
0036 fprintf('\n----- METHOD 1 -----');
0037 fprintf('\nf = %g exitflag = %d\n', f, exitflag);
0038 fprintf('\n var bound shadow prices\n');
0039 fprintf(' x lambda.lower lambda.upper\n');
0040 fprintf('%8.4f %10.4f %12.4f\n', [x lambda.lower lambda.upper]');
0041 fprintf('\nconstraint shadow prices\n');
0042 fprintf('lambda.mu_l lambda.mu_u\n');
0043 fprintf('%8.4f %11.4f\n', [lambda.mu_l lambda.mu_u]');
0044
0045
0046
0047 xmin = [ymin; -Inf(2,1)];
0048 xmax = [ Inf(2,1); zmax];
0049 x0 = [y0; z0];
0050 A = [ A1; A2 0 0];
0051 l = [ b1; -Inf ];
0052 u = [ b1; u2 ];
0053
0054
0055 [x, f, exitflag, output, lambda] = qps_master(Q, [], A, l, u, xmin, xmax, x0);
0056
0057
0058
0059 fprintf('\n----- METHOD 2 -----');
0060 fprintf('\nf = %g exitflag = %d\n', f, exitflag);
0061 fprintf('\n var bound shadow prices\n');
0062 fprintf(' x lambda.lower lambda.upper\n');
0063 fprintf('%8.4f %10.4f %12.4f\n', [x lambda.lower lambda.upper]');
0064 fprintf('\nconstraint shadow prices\n');
0065 fprintf('lambda.mu_l lambda.mu_u\n');
0066 fprintf('%8.4f %11.4f\n', [lambda.mu_l lambda.mu_u]');