Home > matpower7.1 > mp-opt-model > lib > t > qp_ex1.m

qp_ex1

PURPOSE ^

% variable initial values

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% variable initial values

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% variable initial values
0002 y0 = [1; 0];
0003 z0 = [0; 1];
0004 
0005 %% variable lower bounds
0006 ymin = [0; 0];
0007 zmax = [0; 2];
0008 
0009 %% constraint data
0010 A1 = [ 6 1 5 -4 ];  b1 = 4;
0011 A2 = [ 4 9 ];       u2 = 2;
0012 
0013 %% quadratic cost coefficients
0014 Q = [ 8  1 -3 -4;
0015       1  4 -2 -1;
0016      -3 -2  5  4;
0017      -4 -1  4  12  ];
0018 
0019 %% solver options
0020 opt = struct('verbose', 2, 'alg', 'MIPS');
0021 
0022 %%-----  METHOD 1  -----
0023 %% build model
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 %% solve model
0032 [x, f, exitflag, output, lambda] = om.solve();
0033 % [x, f, exitflag, output, lambda] = om.solve(opt)
0034 
0035 %% print results
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 %%-----  METHOD 2  -----
0046 %% assemble model parameters manually
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 %% solve model
0055 [x, f, exitflag, output, lambda] = qps_master(Q, [], A, l, u, xmin, xmax, x0);
0056 % [x, f, exitflag, output, lambda] = qps_master(Q, [], A, l, u, xmin, [], x0, opt)
0057 
0058 %% print results
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]');

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005