Home > matpower7.0 > mips > lib > t > mips_example2.m

mips_example2

PURPOSE ^

SYNOPSIS ^

function mips_example2

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mips_example2
0002 problem = struct( ...
0003     'f_fcn',    @(x)f2(x), ...
0004     'gh_fcn',   @(x)gh2(x), ...
0005     'hess_fcn', @(x, lam, cost_mult)hess2(x, lam, cost_mult), ...
0006     'x0',       [1; 1; 0], ...
0007     'opt',      struct('verbose', 2) ...
0008 );
0009 [x, f, exitflag, output, lambda] = mips(problem);
0010 fprintf('\nf = %g   exitflag = %d\n', f, exitflag);
0011 fprintf('\nx = \n');
0012 fprintf('   %g\n', x);
0013 fprintf('\nlambda.ineqnonlin =\n');
0014 fprintf('   %g\n', lambda.ineqnonlin);
0015 
0016 function [f, df, d2f] = f2(x)
0017 f = -x(1)*x(2) - x(2)*x(3);
0018 if nargout > 1          %% gradient is required
0019     df = -[x(2); x(1)+x(3); x(2)];
0020     if nargout > 2      %% Hessian is required
0021         d2f = -[0 1 0; 1 0 1; 0 1 0];   %% actually not used since
0022     end                                 %% 'hess_fcn' is provided
0023 end
0024 
0025 function [h, g, dh, dg] = gh2(x)
0026 h = [ 1 -1 1; 1 1 1] * x.^2 + [-2; -10];
0027 dh = 2 * [x(1) x(1); -x(2) x(2); x(3) x(3)];
0028 g = []; dg = [];
0029 
0030 function Lxx = hess2(x, lam, cost_mult)
0031 if nargin < 3, cost_mult = 1; end   %% allows to be used with 'fmincon'
0032 mu = lam.ineqnonlin;
0033 Lxx = cost_mult * [0 -1 0; -1 0 -1; 0 -1 0] + ...
0034         [2*[1 1]*mu 0 0; 0 2*[-1 1]*mu 0; 0 0 2*[1 1]*mu];

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005